Method to uniquely identify a method call in code, to test that a sequence of calls is unchanged
<p>We are developing a new interrupt system (in c++), to replace the old inconsistant one.</p>

<p>It works like this:</p>

<ol>
<li><p>A programmer who wants to make his method interruptable accepts a <code>BreakFlag</code> object as an argument to the method.</p></li>
<li><p>At points during the method the programmer checks <code>break_flag.is_set()</code>, and exits and tidies up if it is.</p></li>
</ol>

<p>We want to be able te test that all the orginal calls to <code>break_flag.is_set()</code> remain in the same order, after some change is made to the program. (We count multiple calls in the same loop as one call, so that two operations of different size appear to be the same)</p>

<p>Our first approach was to use the call stack to identify each instance. For example in the code:</p>

<pre><code>void A(BreakFlag&amp; flag) {
  flag.is_set();
  B(flag);
  C(flag);
}

void B(BreakFlag&amp; flag) {
  flag.is_set();
  C(flag);
}

void C(BreakFlag&amp; flag) {
  flag.is_set();
}
</code></pre>

<p>We would look at the call stack each time <code>is_set</code> is called and generate the following sequence for this method:</p>

<pre><code>A
A, B
A, B, C
A, C
</code></pre>

<p>We could then use this to check that this sequence of checks occers every time we test the program, so that somebody could not come along and do this:</p>

<p>void A(BreakFlag&amp; flag) {
      flag.is_set();
      B(flag);
      C(flag);
    }</p>

<pre><code>void B(BreakFlag&amp; flag) {
  flag.is_set();
  //C(flag); // I HAVE COMMENTED THIS OUT BECAUSE I DONT LIKE FLAG!
}

void C(BreakFlag&amp; flag) {
  flag.is_set();
}
</code></pre>

<p>Because it would result in the sequence:</p>

<pre><code>A
A, B
A, C
</code></pre>

<p>Which would not match our original.</p>

<p>The problem that we have, is that the compiler sometimes optomizes in such a way that the call stack changes, which causes our proposed system to register a false failed test since the call stack is not what it is expecting, even though it is correct.</p>

<p>We could solve it by doing something similar to the following:</p>

<pre><code>#define CHECK_FLAG(x) actually_check_flag(__LINE__,__FILE__,x)
</code></pre>

<p>Which would allow us to essentially ID each instance in code.</p>

<p>Other than that we cant think of any way to ID each call to <code>.is_set</code> that wont change in optomized code, can you?</p>
