Skip to content

Commit

Permalink
(#1170) Improve signalHandler go test so it shows failures more frequ…
Browse files Browse the repository at this point in the history
…ently
  • Loading branch information
jrcheli committed Mar 29, 2023
1 parent 8e85d0b commit 6c5f967
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
2 changes: 2 additions & 0 deletions contrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ build/pcre2/libpcre2-posix.a build/pcre2/libpcre2-8.a:
@$(RM) -r build/pcre2
@mkdir build/pcre2
cd build/pcre2 && cmake ../../pcre2 && $(MAKE)
# the pcre2 cmake constants (eg. PCRE2_...) are defined in CMakeLists.txt
# cd build/pcre2 && cmake -DPCRE2_MATCH_LIMIT=500000 -DPCRE2_HEAP_LIMIT=500 -DPCRE2_MATCH_LIMIT_DEPTH=10000 -DPCRE2GREP_SUPPORT_JIT=OFF ../../pcre2 && $(MAKE)
objcopy --redefine-syms redefine_syms.lst build/pcre2/libpcre2-posix.a
objcopy --redefine-syms redefine_syms.lst build/pcre2/libpcre2-8.a
@[ -z "$(CI)" ] || echo "::endgroup::"
Expand Down
13 changes: 7 additions & 6 deletions src/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ get_stack(void)

// We got a spot, but our malloc failed. Put the spot back
// into the unused pool. Stop looping if this happens.
// grab_unused() guarantees that only one thread at a time
// can get here; so this doen't need to ba an atomic operation.
entry->used = FALSE;
if (!atomicCasU64(&entry->used, (uint64_t)TRUE, (uint64_t)FALSE)) {
scopeLogError("get_stack failed to set used to FALSE");
}
break;
}
}
Expand All @@ -357,9 +357,10 @@ free_stack(char *addr)
if (entry->addr == addr) {

// Addr is in the pool. Don't free addr, but set used to false
// to allow reuse. Only one thread can use a stack entry at a
// time so an atomic operation is unnecessary here.
entry->used = FALSE;
// to allow reuse.
if (!atomicCasU64(&entry->used, (uint64_t)TRUE, (uint64_t)FALSE)) {
scopeLogError("free_stack failed to set used to FALSE");
}
return;
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/go/signals/signalHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func genOpenCloseLoop(f_name string) {
}
}

func genConsoleOutput() {
for i :=1; i < LoopLimit; i++ {
fmt.Printf(" %d ", i)
if i % 6 == 0 {
fmt.Println("")
}
}
}

func main() {

sig_channel := make(chan os.Signal, 1)
Expand Down Expand Up @@ -64,6 +73,10 @@ func main() {
genOpenCloseLoop(tmpfile.Name())
}()

go func() {
genConsoleOutput();
}()

<-quit_channel
fmt.Println("Exiting")
}
30 changes: 24 additions & 6 deletions test/integration/go/test_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -815,27 +815,36 @@ endtest
#
starttest signalHandlerStatic
cd /go/signals
scope -z ./signalHandlerStatic 2>${ERR_FILE}&
scope -z ./signalHandlerStatic &>${ERR_FILE}&
SCOPE_PID=$!
ERR+=$?
sleep 0.1

sleep 1
kill -SIGCHLD ${SCOPE_PID}
sleep 1

# verify that process still exists
if ! ps -p ${SCOPE_PID}; then
echo "$SCOPE_PID ps first fail signalHandlerStatic"
ERR+=1
fi

count=$(grep 'bad g' $ERR_FILE | wc -l)
if [ $count -ne 0 ] ; then
echo "$SCOPE_PID bad g seen in $ERR_FILE before sigkill"
cat $ERR_FILE
ERR+=1
fi

while kill -0 ${SCOPE_PID}; do
echo "sending SIGKILL"
kill -SIGKILL ${SCOPE_PID}
sleep 1
done

count=$(grep 'bad g' $ERR_FILE | wc -l)
if [ $count -ne 0 ] ; then
echo "$SCOPE_PID bad g seen in $ERR_FILE"
echo "$SCOPE_PID bad g seen in $ERR_FILE after sigkill"
cat $ERR_FILE
ERR+=1
fi
Expand All @@ -847,27 +856,36 @@ endtest
#
starttest signalHandlerStaticStripped
cd /go/signals
scope -z ./signalHandlerStatic 2>${ERR_FILE}&
scope -z ./signalHandlerStaticStripped &>${ERR_FILE}&
SCOPE_PID=$!
ERR+=$?
sleep 0.1

sleep 1
kill -SIGCHLD ${SCOPE_PID}
sleep 1

# verify that process still exists
if ! ps -p ${SCOPE_PID}; then
echo "$SCOPE_PID ps first fail signalHandlerStaticStripped"
ERR+=1
fi

count=$(grep 'bad g' $ERR_FILE | wc -l)
if [ $count -ne 0 ] ; then
echo "$SCOPE_PID bad g seen in $ERR_FILE before sigkill"
cat $ERR_FILE
ERR+=1
fi

while kill -0 ${SCOPE_PID}; do
echo "sending SIGKILL"
kill -SIGKILL ${SCOPE_PID}
sleep 1
done

count=$(grep 'bad g' $ERR_FILE | wc -l)
if [ $count -ne 0 ] ; then
echo "$SCOPE_PID bad g seen in $ERR_FILE"
echo "$SCOPE_PID bad g seen in $ERR_FILE after sigkill"
cat $ERR_FILE
ERR+=1
fi
Expand Down

0 comments on commit 6c5f967

Please sign in to comment.