Skip to content

Commit ab50343

Browse files
authored
Merge pull request #48714 from smuzaffar/unittest-gdb
[GDB] Added unit tests for gdb and running cmsTraceFunction
2 parents 64ec912 + a6e1880 commit ab50343

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

Utilities/ReleaseScripts/test/BuildFile.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<test name="TestSCRAM" command="run.sh"/>
22
<test name="SCRAM_TestPass" command="true"/>
33
<test name="SCRAM_TestFail" command="! false"/>
4+
<test name="test-gdb-python" command="gdb/test-gdb-python.sh">
5+
<use name="gdb"/>
6+
</test>
7+
<test name="test-cmsTraceFunction-setenv" command="gdb/test-cmsTraceFunction-setenv.sh">
8+
<use name="gdb"/>
9+
</test>
410
<test name="test-clang-tidy" command="test-clang-tidy.sh">
511
<use name="llvm"/>
612
</test>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <stdlib.h>
4+
5+
class ScheduleItems {
6+
public:
7+
ScheduleItems() {}
8+
void initMisc();
9+
};
10+
11+
void ScheduleItems::initMisc() { std::cout << "ScheduleItems::initMisc() called" << std::endl; }
12+
13+
void my_setenv(const char* env, const char* value) {
14+
setenv(env, value, 1);
15+
std::cout << "setenv() called" << std::endl;
16+
std::cout << env << "=" << std::getenv(env) << std::endl;
17+
}
18+
19+
int main() {
20+
my_setenv("FOO", "1");
21+
ScheduleItems obj;
22+
obj.initMisc();
23+
my_setenv("FOO", "2");
24+
my_setenv("FOO", "3");
25+
return 0;
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -ex
2+
g++ -o test-cmsTraceFunction-setenv $(dirname $0)/test-cmsTraceFunction-setenv.cpp
3+
cmsTraceFunction --startAfterFunction ScheduleItems::initMisc setenv ./test-cmsTraceFunction-setenv 2>&1 | grep setenv > setenv.log
4+
rm -f test-cmsTraceFunction-setenv
5+
setenv_count=$(grep '^setenv() called' setenv.log | wc -l)
6+
break_setenv=$(grep 'Breakpoint .* in setenv ()' setenv.log | wc -l)
7+
if [ ${setenv_count} != 3 ] || [ ${break_setenv} != 2 ] ; then
8+
exit 1
9+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash -ex
2+
gdb_python=$(gdb -q -ex 'python exec("import sys;print(sys.executable)")' -ex quit)
3+
cmssw_python=$(scram tool tag python3 PYTHON3_BASE)/bin
4+
cmssw_python=$(realpath ${cmssw_python})/python
5+
if [ "${gdb_python}" != "${cmssw_python}" ] ; then
6+
echo "python used by GDB and CMSSW are not same"
7+
exit 1
8+
else
9+
echo "CMSSW/GDB python OK"
10+
fi

0 commit comments

Comments
 (0)