Add unit test: run in nonzero heap/stack env.

This commit is contained in:
nil0x42 2015-03-08 12:48:09 +01:00
parent 984f6f9408
commit 5a4a92f2b3
2 changed files with 82 additions and 0 deletions

26
tests/bugtraq.sh Executable file
View File

@ -0,0 +1,26 @@
#! /bin/bash
#
# This file tests for possible bugs
#
. funcs.sh
# ---------------------------- Tests -----------------------------------
function test_with_nonzero_heap_and_stack {
compile src/nonzero_heap_stack.c
if ! timeout 1 ./test; then
err "Fail running on nonzero heap and stack"
exit 1
else
return
fi
}
# Run tests
test_with_nonzero_heap_and_stack
echo "No errors"

View File

@ -0,0 +1,56 @@
/*
* Try to run thpool with a non-zero heap and stack
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include "../../thpool.h"
void task(){
printf("Thread #%u working on task\n", (int)pthread_self());
}
void nonzero_stack(){
char buf[40096];
memset(buf, 0x80, 40096);
}
void nonzero_heap(){
int i;
void *ptrs[200];
for (i=0; i<200; i++){
ptrs[i] = malloc((i+1) << 4);
if (ptrs[i])
memset(ptrs[i], 0x80, (i+1) << 4);
}
for (i=0; i<200; i++){
free(ptrs[i]);
}
}
int main(){
nonzero_stack();
nonzero_heap();
puts("Making threadpool with 4 threads");
threadpool thpool = thpool_init(4);
puts("Adding 20 tasks to threadpool");
int i;
for (i=0; i<20; i++){
thpool_add_work(thpool, (void*)task, NULL);
};
puts("Killing threadpool");
thpool_destroy(thpool);
return 0;
}