Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Utilities/ReleaseScripts/test/gdb/test-cmsTraceFunction-putenv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <stdlib.h>

class ScheduleItems {
public:
ScheduleItems() {}
void initMisc();
};

void ScheduleItems::initMisc() { std::cout << "ScheduleItems::initMisc() called" << std::endl; }

void my_putenv(const char* env, char* put) {
putenv(put);
std::cout << "putenv() called" << std::endl;
std::cout << env << "=" << std::getenv(env) << std::endl;
}

int main() {
// putenv() expects modifiable char array that lives throughout the program
char* foo1 = new char[10];
char* foo2 = new char[10];
char* foo3 = new char[10];
std::strncpy(foo1, "FOO=1", 10);
std::strncpy(foo2, "FOO=2", 10);
std::strncpy(foo3, "FOO=3", 10);

my_putenv("FOO", foo1);
ScheduleItems obj;
obj.initMisc();
my_putenv("FOO", foo2);
my_putenv("FOO", foo3);
return 0;
}
60 changes: 52 additions & 8 deletions Utilities/ReleaseScripts/test/gdb/test-cmsTraceFunction-setenv.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
#!/bin/bash -ex
g++ -o test-cmsTraceFunction-setenv $(dirname $0)/test-cmsTraceFunction-setenv.cpp
cmsTraceFunction --startAfterFunction ScheduleItems::initMisc setenv ./test-cmsTraceFunction-setenv 2>&1 | grep setenv > setenv.log
rm -f test-cmsTraceFunction-setenv
setenv_count=$(grep '^setenv() called' setenv.log | wc -l)
break_setenv=$(grep 'Breakpoint .* in setenv ()' setenv.log | wc -l)
if [ ${setenv_count} != 3 ] || [ ${break_setenv} != 2 ] ; then
exit 1
fi

TRACE="cmsTraceFunction --startAfterFunction ScheduleItems::initMisc setenv -f putenv"

check_func() {
local func_name="$1"
local src_name="$2"
local trace_opts="$3"
local exe_name="test-cmsTraceFunction-${func_name}"
local raw_log="${func_name}_raw.log"
local log="${func_name}.log"

g++ -o "$exe_name" "$(dirname $0)/$src_name"
set +e
$TRACE $trace_opts ./$exe_name 2>&1 > "$raw_log"
local ret=$?
set -e
grep "$func_name" "$raw_log" > "$log"

if [ ${trace_opts} = "--abort" ]; then
call_count_expected=1
break_count_expected=1

if [ ${ret} = 0 ]; then
echo "cmsTraceFunction exited with exit code 0, expected non-zero exit code"
exit 1
fi
else
call_count_expected=3
break_count_expected=2

if [ ${ret} != 0 ]; then
echo "cmsTraceFunction exited with exit code $ret, expected zero exit code"
exit 1
fi
fi

local call_count=$(grep -c "^${func_name}() called" "$log")
local break_count=$(grep -c "Breakpoint .* in ${func_name} ()" "$log")
if [ ${call_count} != ${call_count_expected} ] || [ ${break_count} != ${break_count_expected} ] ; then
echo "Unexpected number of ${func_name} calls ${call_count} or breakpoints ${break_count}; expecting calls ${call_count_expected} and breakpoints ${break_count_expected}"
exit 1
fi
}

# Check setenv
check_func "setenv" "test-cmsTraceFunction-setenv.cpp" ""
check_func "setenv" "test-cmsTraceFunction-setenv.cpp" "--abort"


# Check putenv
check_func "putenv" "test-cmsTraceFunction-putenv.cpp" ""
check_func "putenv" "test-cmsTraceFunction-putenv.cpp" "--abort"