Skip to content

Commit

Permalink
scrGroup is now a pointer typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeldan committed Aug 22, 2023
1 parent e1d10d9 commit 430d4aa
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 90 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ All of the functionality can be accessed by
Every test must be part of a group. You can create a group by

```c
scrGroup *group;
scrGroup group;

group = scrGroupCreate(NULL, NULL);
```
Expand Down Expand Up @@ -170,7 +170,7 @@ The signature of `scrGroupAddTest` is

```c
void
scrGroupAddTest(scrGroup *group, const char *name, scrTestFn test_fn, const scrTestOptions *options);
scrGroupAddTest(scrGroup group, const char *name, scrTestFn test_fn, const scrTestOptions *options);
```
where
Expand Down Expand Up @@ -265,7 +265,7 @@ and then patch `malloc` with
```c
bool
scrGroupPatchFunction(scrGroup *group, const char *func_name, const char *file_substring, void *new_func);
scrGroupPatchFunction(scrGroup group, const char *func_name, const char *file_substring, void *new_func);
```

Here, `new_func` would be a function pointer to `fake_malloc`. E.g.,
Expand Down
4 changes: 4 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.7.0:
- Monkeypatching can now be selectively applied to ELF files.
- scrGroup is now a pointer typedef.

0.6.2:
- Fixed an integer comparison error for i386 builds.

Expand Down
8 changes: 4 additions & 4 deletions docs/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ <h3><a id="index_s" name="index_s"></a>- s -</h3><ul>
<li>SCR_TF_XFAIL&#160;:&#160;<a class="el" href="run_8h.html#af510b4137d4ff6b0abbd8fcbac6b6f92">run.h</a></li>
<li>scrCtxCleanupFn&#160;:&#160;<a class="el" href="run_8h.html#a0ddbd6caab0df72aea82c68428d9578a">run.h</a></li>
<li>scrCtxCreateFn&#160;:&#160;<a class="el" href="run_8h.html#a33a9c3f5723dacf090e0117092404b88">run.h</a></li>
<li>scrGroup&#160;:&#160;<a class="el" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">run.h</a></li>
<li>scrGroupAddTest()&#160;:&#160;<a class="el" href="run_8h.html#a0ac327eb399ec3e6f882c7aca1310e06">run.h</a></li>
<li>scrGroupCreate()&#160;:&#160;<a class="el" href="run_8h.html#aa7aed75585fe45f023ce488bdd83706f">run.h</a></li>
<li>scrGroup&#160;:&#160;<a class="el" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">run.h</a></li>
<li>scrGroupAddTest()&#160;:&#160;<a class="el" href="run_8h.html#a38b44f8ac530738e72643a68c9cc70d7">run.h</a></li>
<li>scrGroupCreate()&#160;:&#160;<a class="el" href="run_8h.html#ac19ec14833b015c6ccbd424d20cfeb1e">run.h</a></li>
<li>scrGroupCtx()&#160;:&#160;<a class="el" href="test_8h.html#a86ea3c087ee5b72a0b63c7fa1f4a3fb5">test.h</a></li>
<li>scrGroupPatchFunction()&#160;:&#160;<a class="el" href="run_8h.html#afe92cbe7f530db52f66e512a0f09a137">run.h</a></li>
<li>scrGroupPatchFunction()&#160;:&#160;<a class="el" href="run_8h.html#a8de3f03238ed08517044288cb6768e84">run.h</a></li>
<li>scrOptions&#160;:&#160;<a class="el" href="run_8h.html#a86df619ddcdab198dd59ea817de931e6">run.h</a></li>
<li>scrPatchedFunction()&#160;:&#160;<a class="el" href="test_8h.html#a43ca6cb70a568895934fd799268753a3">test.h</a></li>
<li>scrRun()&#160;:&#160;<a class="el" href="run_8h.html#af1680b15d3118f62b2d457e061ee22a4">run.h</a></li>
Expand Down
6 changes: 3 additions & 3 deletions docs/globals_func.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@

<div class="contents">
&#160;<ul>
<li>scrGroupAddTest()&#160;:&#160;<a class="el" href="run_8h.html#a0ac327eb399ec3e6f882c7aca1310e06">run.h</a></li>
<li>scrGroupCreate()&#160;:&#160;<a class="el" href="run_8h.html#aa7aed75585fe45f023ce488bdd83706f">run.h</a></li>
<li>scrGroupAddTest()&#160;:&#160;<a class="el" href="run_8h.html#a38b44f8ac530738e72643a68c9cc70d7">run.h</a></li>
<li>scrGroupCreate()&#160;:&#160;<a class="el" href="run_8h.html#ac19ec14833b015c6ccbd424d20cfeb1e">run.h</a></li>
<li>scrGroupCtx()&#160;:&#160;<a class="el" href="test_8h.html#a86ea3c087ee5b72a0b63c7fa1f4a3fb5">test.h</a></li>
<li>scrGroupPatchFunction()&#160;:&#160;<a class="el" href="run_8h.html#afe92cbe7f530db52f66e512a0f09a137">run.h</a></li>
<li>scrGroupPatchFunction()&#160;:&#160;<a class="el" href="run_8h.html#a8de3f03238ed08517044288cb6768e84">run.h</a></li>
<li>scrPatchedFunction()&#160;:&#160;<a class="el" href="test_8h.html#a43ca6cb70a568895934fd799268753a3">test.h</a></li>
<li>scrRun()&#160;:&#160;<a class="el" href="run_8h.html#af1680b15d3118f62b2d457e061ee22a4">run.h</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/globals_type.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
&#160;<ul>
<li>scrCtxCleanupFn&#160;:&#160;<a class="el" href="run_8h.html#a0ddbd6caab0df72aea82c68428d9578a">run.h</a></li>
<li>scrCtxCreateFn&#160;:&#160;<a class="el" href="run_8h.html#a33a9c3f5723dacf090e0117092404b88">run.h</a></li>
<li>scrGroup&#160;:&#160;<a class="el" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">run.h</a></li>
<li>scrGroup&#160;:&#160;<a class="el" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">run.h</a></li>
<li>scrOptions&#160;:&#160;<a class="el" href="run_8h.html#a86df619ddcdab198dd59ea817de931e6">run.h</a></li>
<li>scrStats&#160;:&#160;<a class="el" href="run_8h.html#a0ab54a6f620fd8de5f8f12228a905406">run.h</a></li>
<li>scrTestFn&#160;:&#160;<a class="el" href="run_8h.html#a78714973fe7a20ca16e1cf263d6035e4">run.h</a></li>
Expand Down
24 changes: 12 additions & 12 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ <h1><a class="anchor" id="autotoc_md0"></a>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="scrutiny_8h.html">scrutiny/scrutiny.h</a>&gt;</span></div>
<div class="ttc" id="ascrutiny_8h_html"><div class="ttname"><a href="scrutiny_8h.html">scrutiny.h</a></div><div class="ttdoc">Master include file.</div></div>
</div><!-- fragment --><p >Every test must be part of a group. You can create a group by</p>
<div class="fragment"><div class="line"><a class="code hl_typedef" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">scrGroup</a> *group;</div>
<div class="fragment"><div class="line"><a class="code hl_typedef" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">scrGroup</a> group;</div>
<div class="line"> </div>
<div class="line">group = <a class="code hl_function" href="run_8h.html#aa7aed75585fe45f023ce488bdd83706f">scrGroupCreate</a>(NULL, NULL);</div>
<div class="ttc" id="arun_8h_html_aa7aed75585fe45f023ce488bdd83706f"><div class="ttname"><a href="run_8h.html#aa7aed75585fe45f023ce488bdd83706f">scrGroupCreate</a></div><div class="ttdeci">scrGroup * scrGroupCreate(scrCtxCreateFn create_fn, scrCtxCleanupFn cleanup_fn) SCR_EXPORT SCR_MALLOC</div><div class="ttdoc">Creates a new test group.</div></div>
<div class="ttc" id="arun_8h_html_ac6666827e21523e7bc29f69e17650ef9"><div class="ttname"><a href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">scrGroup</a></div><div class="ttdeci">struct scrGroup scrGroup</div><div class="ttdoc">An opaque structure encapsulating each testing group.</div><div class="ttdef"><b>Definition:</b> run.h:15</div></div>
<div class="line">group = <a class="code hl_function" href="run_8h.html#ac19ec14833b015c6ccbd424d20cfeb1e">scrGroupCreate</a>(NULL, NULL);</div>
<div class="ttc" id="arun_8h_html_ac19ec14833b015c6ccbd424d20cfeb1e"><div class="ttname"><a href="run_8h.html#ac19ec14833b015c6ccbd424d20cfeb1e">scrGroupCreate</a></div><div class="ttdeci">scrGroup scrGroupCreate(scrCtxCreateFn create_fn, scrCtxCleanupFn cleanup_fn) SCR_EXPORT SCR_MALLOC</div><div class="ttdoc">Creates a new test group.</div></div>
<div class="ttc" id="arun_8h_html_ae54cb7e18b1b20683e0480e98c0f6c31"><div class="ttname"><a href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">scrGroup</a></div><div class="ttdeci">struct scrGroupStruct * scrGroup</div><div class="ttdoc">An opaque structure encapsulating each testing group.</div><div class="ttdef"><b>Definition:</b> run.h:15</div></div>
</div><!-- fragment --><p >After that, you can define a test function:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> my_test(<span class="keywordtype">void</span>) {</div>
<div class="line"> ...</div>
<div class="line">}</div>
</div><!-- fragment --><p >and add it to a group:</p>
<div class="fragment"><div class="line"><a class="code hl_function" href="run_8h.html#a0ac327eb399ec3e6f882c7aca1310e06">scrGroupAddTest</a>(group, <span class="stringliteral">&quot;Test name&quot;</span>, my_test, NULL);</div>
<div class="ttc" id="arun_8h_html_a0ac327eb399ec3e6f882c7aca1310e06"><div class="ttname"><a href="run_8h.html#a0ac327eb399ec3e6f882c7aca1310e06">scrGroupAddTest</a></div><div class="ttdeci">void scrGroupAddTest(scrGroup *group, const char *name, scrTestFn test_fn, const scrTestOptions *options) SCR_EXPORT SCR_NONNULL(1</div><div class="ttdoc">Adds a test to a group.</div></div>
<div class="fragment"><div class="line"><a class="code hl_function" href="run_8h.html#a38b44f8ac530738e72643a68c9cc70d7">scrGroupAddTest</a>(group, <span class="stringliteral">&quot;Test name&quot;</span>, my_test, NULL);</div>
<div class="ttc" id="arun_8h_html_a38b44f8ac530738e72643a68c9cc70d7"><div class="ttname"><a href="run_8h.html#a38b44f8ac530738e72643a68c9cc70d7">scrGroupAddTest</a></div><div class="ttdeci">void scrGroupAddTest(scrGroup group, const char *name, scrTestFn test_fn, const scrTestOptions *options) SCR_EXPORT SCR_NONNULL(1</div><div class="ttdoc">Adds a test to a group.</div></div>
</div><!-- fragment --><p >Once you have added all of the tests, you can run them by</p>
<div class="fragment"><div class="line"><a class="code hl_function" href="run_8h.html#af1680b15d3118f62b2d457e061ee22a4">scrRun</a>(NULL, NULL);</div>
<div class="ttc" id="arun_8h_html_af1680b15d3118f62b2d457e061ee22a4"><div class="ttname"><a href="run_8h.html#af1680b15d3118f62b2d457e061ee22a4">scrRun</a></div><div class="ttdeci">void bool int scrRun(const scrOptions *options, scrStats *stats) SCR_EXPORT</div><div class="ttdoc">Runs all of the tests.</div></div>
Expand Down Expand Up @@ -194,7 +194,7 @@ <h1><a class="anchor" id="autotoc_md2"></a>
Test parameters</h1>
<p >The signature of <code>scrGroupAddTest</code> is</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span></div>
<div class="line"><a class="code hl_function" href="run_8h.html#a0ac327eb399ec3e6f882c7aca1310e06">scrGroupAddTest</a>(<a class="code hl_typedef" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">scrGroup</a> *group, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code hl_typedef" href="run_8h.html#a78714973fe7a20ca16e1cf263d6035e4">scrTestFn</a> test_fn, <span class="keyword">const</span> <a class="code hl_struct" href="structscrTestOptions.html">scrTestOptions</a> *options);</div>
<div class="line"><a class="code hl_function" href="run_8h.html#a38b44f8ac530738e72643a68c9cc70d7">scrGroupAddTest</a>(<a class="code hl_typedef" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">scrGroup</a> group, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code hl_typedef" href="run_8h.html#a78714973fe7a20ca16e1cf263d6035e4">scrTestFn</a> test_fn, <span class="keyword">const</span> <a class="code hl_struct" href="structscrTestOptions.html">scrTestOptions</a> *options);</div>
<div class="ttc" id="arun_8h_html_a78714973fe7a20ca16e1cf263d6035e4"><div class="ttname"><a href="run_8h.html#a78714973fe7a20ca16e1cf263d6035e4">scrTestFn</a></div><div class="ttdeci">void scrTestFn(void)</div><div class="ttdoc">The signature for a test function.</div><div class="ttdef"><b>Definition:</b> run.h:33</div></div>
<div class="ttc" id="astructscrTestOptions_html"><div class="ttname"><a href="structscrTestOptions.html">scrTestOptions</a></div><div class="ttdef"><b>Definition:</b> run.h:35</div></div>
</div><!-- fragment --><p >where</p>
Expand Down Expand Up @@ -226,8 +226,8 @@ <h1><a class="anchor" id="autotoc_md3"></a>
<div class="ttc" id="astructscrOptions_html_a8467b749302edfa3c9edbba81ad66c44"><div class="ttname"><a href="structscrOptions.html#a8467b749302edfa3c9edbba81ad66c44">scrOptions::flags</a></div><div class="ttdeci">unsigned int flags</div><div class="ttdef"><b>Definition:</b> run.h:45</div></div>
</div><!-- fragment --><p >If the <code>options</code> argument is <code>NULL</code>, then default values will be used (i.e., <code>NULL</code> and <code>0</code>).</p>
<p >By default, each group context is equal to the global context. However, you can pass function pointers to <code>scrGroupCreate</code> which can set up and tear down a group context. The signature of <code>scrGroupCreate</code> is</p>
<div class="fragment"><div class="line"><a class="code hl_typedef" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">scrGroup</a> *</div>
<div class="line"><a class="code hl_function" href="run_8h.html#aa7aed75585fe45f023ce488bdd83706f">scrGroupCreate</a>(<a class="code hl_typedef" href="run_8h.html#a33a9c3f5723dacf090e0117092404b88">scrCtxCreateFn</a> create_fn, <a class="code hl_typedef" href="run_8h.html#a0ddbd6caab0df72aea82c68428d9578a">scrCtxCleanupFn</a> cleanup_fn);</div>
<div class="fragment"><div class="line"><a class="code hl_typedef" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">scrGroup</a> *</div>
<div class="line"><a class="code hl_function" href="run_8h.html#ac19ec14833b015c6ccbd424d20cfeb1e">scrGroupCreate</a>(<a class="code hl_typedef" href="run_8h.html#a33a9c3f5723dacf090e0117092404b88">scrCtxCreateFn</a> create_fn, <a class="code hl_typedef" href="run_8h.html#a0ddbd6caab0df72aea82c68428d9578a">scrCtxCleanupFn</a> cleanup_fn);</div>
<div class="ttc" id="arun_8h_html_a0ddbd6caab0df72aea82c68428d9578a"><div class="ttname"><a href="run_8h.html#a0ddbd6caab0df72aea82c68428d9578a">scrCtxCleanupFn</a></div><div class="ttdeci">void scrCtxCleanupFn(void *)</div><div class="ttdoc">The signature for a group context cleanup function.</div><div class="ttdef"><b>Definition:</b> run.h:27</div></div>
<div class="ttc" id="arun_8h_html_a33a9c3f5723dacf090e0117092404b88"><div class="ttname"><a href="run_8h.html#a33a9c3f5723dacf090e0117092404b88">scrCtxCreateFn</a></div><div class="ttdeci">void * scrCtxCreateFn(void *)</div><div class="ttdoc">The signature for a group context creation function.</div><div class="ttdef"><b>Definition:</b> run.h:21</div></div>
</div><!-- fragment --><p >where</p>
Expand Down Expand Up @@ -255,10 +255,10 @@ <h1><a class="anchor" id="autotoc_md5"></a>
<div class="line">}</div>
</div><!-- fragment --><p >and then patch <code>malloc</code> with</p>
<div class="fragment"><div class="line"><span class="keywordtype">bool</span></div>
<div class="line"><a class="code hl_function" href="run_8h.html#afe92cbe7f530db52f66e512a0f09a137">scrGroupPatchFunction</a>(<a class="code hl_typedef" href="run_8h.html#ac6666827e21523e7bc29f69e17650ef9">scrGroup</a> *group, <span class="keyword">const</span> <span class="keywordtype">char</span> *func_name, <span class="keyword">const</span> <span class="keywordtype">char</span> *file_substring, <span class="keywordtype">void</span> *new_func);</div>
<div class="ttc" id="arun_8h_html_afe92cbe7f530db52f66e512a0f09a137"><div class="ttname"><a href="run_8h.html#afe92cbe7f530db52f66e512a0f09a137">scrGroupPatchFunction</a></div><div class="ttdeci">void bool scrGroupPatchFunction(scrGroup *group, const char *func_name, const char *file_substring, void *new_func) SCR_EXPORT SCR_NONNULL(1</div><div class="ttdoc">Enables monkeypatching of a function for all of a group's tests.</div></div>
<div class="line"><a class="code hl_function" href="run_8h.html#a8de3f03238ed08517044288cb6768e84">scrGroupPatchFunction</a>(<a class="code hl_typedef" href="run_8h.html#ae54cb7e18b1b20683e0480e98c0f6c31">scrGroup</a> group, <span class="keyword">const</span> <span class="keywordtype">char</span> *func_name, <span class="keyword">const</span> <span class="keywordtype">char</span> *file_substring, <span class="keywordtype">void</span> *new_func);</div>
<div class="ttc" id="arun_8h_html_a8de3f03238ed08517044288cb6768e84"><div class="ttname"><a href="run_8h.html#a8de3f03238ed08517044288cb6768e84">scrGroupPatchFunction</a></div><div class="ttdeci">void bool scrGroupPatchFunction(scrGroup group, const char *func_name, const char *file_substring, void *new_func) SCR_EXPORT SCR_NONNULL(1</div><div class="ttdoc">Enables monkeypatching of a function for all of a group's tests.</div></div>
</div><!-- fragment --><p >Here, <code>new_func</code> would be a function pointer to <code>fake_malloc</code>. E.g.,</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> ( !<a class="code hl_function" href="run_8h.html#afe92cbe7f530db52f66e512a0f09a137">scrGroupPatchFunction</a>(group, <span class="stringliteral">&quot;malloc&quot;</span>, NULL, fake_malloc) ) {</div>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> ( !<a class="code hl_function" href="run_8h.html#a8de3f03238ed08517044288cb6768e84">scrGroupPatchFunction</a>(group, <span class="stringliteral">&quot;malloc&quot;</span>, NULL, fake_malloc) ) {</div>
<div class="line"> <span class="comment">// handle the error</span></div>
<div class="line">}</div>
</div><!-- fragment --><p >This test would then pass:</p>
Expand Down
Loading

0 comments on commit 430d4aa

Please sign in to comment.