Skip to content

Commit

Permalink
Add a bit more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdecker committed Mar 26, 2024
1 parent 4a9065c commit d064578
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion _projects/software-testing/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ layout: markdown
* Coverage information is inserted as follows with an example provided after. All insertions are plain text nodes (token type)
* `syntax_tree::main_header` inserts an include of *coverage_map.hpp* at the start of the file. In addition, `syntax_tree::main_header` will also insert global variable declarations (one for each file) with type *coverage_map_t* after the include. The method parameter contains the names of these variable for you.
* `syntax_tree:file_header` also inserts an include of *coverage_map.hpp* at the start of the file. However, it inserts one `extern` declaration referencing one of the variables declared in the main file. The name of the variable is passed to the function for you.
* `syntax_tree::main_report` is run on the main file. It will have to search for the function named `main` and before the return statement (for simplicity, there is guaranteed to be only one return statement, and it will be directly in the function body and not nested in a statement), it will call print on each of the global variables inserted by `syntax_tree::main_header`. The names of the variables are provided for you as a parameter.
* `syntax_tree::main_report` is run on the main file. It will have to search for the function named `main` and before the return statement (for simplicity, there is guaranteed to be only one return statement, and it will be directly in the function body (i.e., \<body_content>) and not nested in a statement), it will call print on each of the global variables inserted by `syntax_tree::main_header`. The names of the variables are provided for you as a parameter.
* `syntax_tree::instrument_functions` inserts all the coverage instrumentations using `syntax_tree::count_elements` and `syntax_tree::instrument_statements` as helper methods. For each function found (you will have to search for each), first, `syntax_tree::instrument_functions` finds the function body and then the body's content (i.e., \<body_content>) where it inserts a call to append on the variable name provided as a parameter. The arguments to this call are the name of the function (use `__FUNCTION__` for simplicity) and the number of statements (and conditions if you are doing the extra credit). Use `syntax_tree::count_elements` to get this number. Lastly, it calls `syntax_tree::instrument_statements` to insert statement coverage (and condition coverage if you are doing the extra credit).
* `syntax_tree::count_elements` counts the number of expression statements (`expr_stmt`), declaration statements (`decl_stmt`), and, if you are doing the extra credit, conditions (`condition`). This is a recursive function. `is_coverage_tag` may be of use. Make sure to call this on the function element.
* `syntax_tree::instrument_statements` inserts calls to `executed` immediately after each expression statements (`expr_stmt`) and declaration statements (`decl_stmt`). If doing the extra credit, it also inserts a call to `executed` at the start of each condition (`condition`). Some conditions have a `(` and others do not that you will have to place the call after. The variable the call is placed on is provided as a parameter to `syntax_tree::instrument_statements`. Additionally, the second parameter to `executed` is a unique (by function) identifier for that statement/condition. The parameter `current_statement_number` to `syntax_tree::instrument_statements` is used to provide this unique identifier. Make sure to increment after each call to executed is inserted. This is a recursive function.
Expand Down

0 comments on commit d064578

Please sign in to comment.