RE: devchk ideas
ShrikantGangoda <[email protected]> Fri, 28 Oct 2005 12:49:47 +0530
| Newsgroups | gmane.linux.lsb.test-suite |
|---|---|
| Organization | Codito Technologies Pvt. Ltd. |
| Message-ID | <[email protected]> |
On Thu, 2005-10-27 at 11:07 -0700, Jain, Nilesh wrote:
> On Thu, 2005-10-27 at 09:42 -0700, Banginwar, Rajesh wrote:
> > No, this will work only with functions and global variables.
> >
> > For macros, we will have to come up with different strategy. I believe
> > except for integer, float or string macros, not much is tested in
> > devchk. Many of the macros are marked as unknown for this purpose. I
> > have one suggestion for this: For macros like #define foo bar we can
> > introduce a new type string2 which will allow us to do string
> > comparison. This is in addition to string type for macros like #define
> > foo "bar".
>
> String comparison will not be possible because #define stored in the
> database is not string identical, they are functionally identical.
>
If they are string identical then also it has some issues. I tried to
did that with following code
/* Code added in mktests script */
----------------------------------
if( $centry{'Ctype'} eq 'macro') {
print TESTS "#ifdef $centry{'Cname'}\n";
print TESTS "#define MACRO_C(x) #x\n";
print TESTS "#define MACRO_A(x) MACRO_C(x)\n";
print TESTS "#define MACRO_B(x) x\n";
print TESTS
"\tCompareMacroConstant($centry{'Cname'},MACRO_B(MACRO_A(($centry{'Cname'}))),\"\(".$centry{'ACvalue'}."\)\")\n";
print TESTS "#else\n";
print TESTS "Msg( \"Error: Constant not found:
$centry{'Cname'}\\n\");\n";
print TESTS "cnt++;\n";
print TESTS "#endif\n\n";
}
In above code MACRO_A MACRO_B and MACRO_C are used to convert macro
value into string (within double quotes ).
/* code added in hdrchk.h */
----------------------------
#define CompareMacroConstant(const,origval,value) \
cnt++; \
Log("subtest %d\n", cnt); \
Log("Purpose: Compare String Constant "#const" has value %s\n",
value); \
if( strcmp(origval,value) != 0 ) { \
Msg(#const " is %s instead of expected %s\n", origval, value); \
HDRCHKTEST_FAIL \
} \
else { \
HDRCHKTEST_PASS \
}
Example:
=========
#define TEST(VAR1,VAR2) (VAR1 << VAR2)
then we get "(VAR1 << VAR2)" (as a string) instead of (VAR1 << Var2)
using the 3 macros. Now we can use strcmp() to compare above original
value and value from DB which is also a string.
But if in above example we replace (VAR1 << VAR2) by any other macro
then we get the value of that macro.
#define TEST(VAR1) TEST1(VAR1+2,VAR2)
#define TEST1(VAR_A,VAR_B) (VAR_A + VAR_B)
then we get "(VAR_A + VAR_B)" from above code and "TEST1(VAR1+2,VAR2)"
from DB which gives us wrong results.
Any idea to sort this issue ??
one way i am trying out is by getting the value of macro TEST1(VAR1
+2,VAR2) from DB so that we get the final values that is "(VAR_A +
VAR_B)" from both original definition and DB.
-Shrikant