address some holes in script coverage

This commit is contained in:
Vern Paxson 2022-05-03 10:47:07 -07:00
parent 2bb4e696e1
commit ca32cab6cb
3 changed files with 16 additions and 10 deletions

View file

@ -127,27 +127,27 @@ bool ScriptCoverageManager::WriteStats()
return false;
}
for ( list<Stmt*>::const_iterator it = stmts.begin(); it != stmts.end(); ++it )
for ( auto s : stmts )
{
ODesc location_info;
(*it)->GetLocationInfo()->Describe(&location_info);
s->GetLocationInfo()->Describe(&location_info);
ODesc desc_info;
(*it)->Describe(&desc_info);
s->Describe(&desc_info);
string desc(desc_info.Description());
canonicalize_desc cd{delim};
for_each(desc.begin(), desc.end(), cd);
pair<string, string> location_desc(location_info.Description(), desc);
if ( usage_map.find(location_desc) != usage_map.end() )
usage_map[location_desc] += (*it)->GetAccessCount();
usage_map[location_desc] += s->GetAccessCount();
else
usage_map[location_desc] = (*it)->GetAccessCount();
usage_map[location_desc] = s->GetAccessCount();
}
map<pair<string, string>, uint64_t>::const_iterator it;
for ( it = usage_map.begin(); it != usage_map.end(); ++it )
for ( auto& um : usage_map )
{
fprintf(f, "%" PRIu64 "%c%s%c%s\n", it->second, delim, it->first.first.c_str(), delim,
it->first.second.c_str());
fprintf(f, "%" PRIu64 "%c%s%c%s\n", um.second, delim, um.first.first.c_str(), delim,
um.first.second.c_str());
}
fclose(f);

View file

@ -258,7 +258,7 @@ ExprListStmt::~ExprListStmt() = default;
ValPtr ExprListStmt::Exec(Frame* f, StmtFlowType& flow)
{
last_access = run_state::network_time;
RegisterAccess();
flow = FLOW_NEXT;
auto vals = eval_list(f, l.get());
@ -325,7 +325,6 @@ static void print_log(const std::vector<ValPtr>& vals)
ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals, StmtFlowType& /* flow */)
{
RegisterAccess();
do_print_stmt(vals);
return nullptr;
}

View file

@ -1665,28 +1665,33 @@ stmt:
{
set_location(@1, @4);
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive<NullStmt>());
script_coverage_mgr.AddStmt($$);
}
| TOK_IF '(' expr ')' stmt TOK_ELSE stmt
{
set_location(@1, @4);
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7});
script_coverage_mgr.AddStmt($$);
}
| TOK_SWITCH expr '{' case_list '}'
{
set_location(@1, @2);
$$ = new SwitchStmt({AdoptRef{}, $2}, $4);
script_coverage_mgr.AddStmt($$);
}
| for_head stmt
{
$1->AsForStmt()->AddBody({AdoptRef{}, $2});
script_coverage_mgr.AddStmt($1);
}
| TOK_WHILE '(' expr ')' stmt
{
$$ = new WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5});
script_coverage_mgr.AddStmt($$);
}
| TOK_NEXT ';' opt_no_test
@ -1762,6 +1767,7 @@ stmt:
| when_clause
{
$$ = new WhenStmt($1);
script_coverage_mgr.AddStmt($$);
}
| index_slice '=' expr ';' opt_no_test
@ -1786,6 +1792,7 @@ stmt:
{
set_location(@1, @1);
$$ = new NullStmt;
script_coverage_mgr.AddStmt($$);
}
| conditional