Removed submodules

This commit is contained in:
2026-05-31 14:34:00 -04:00
commit 46c36b11da
352 changed files with 14792 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
#
# Simple Test Makefile
# Mike Lam, James Madison University, August 2016
#
# This version of the Makefile includes support for building a test suite. The
# recommended framework is Check (http://check.sourceforge.net/). To build and
# run the test suite, execute the "test" target. The test suite must be located
# in a module called "testsuite". The MODS, LIBS, and OBJS variables work as
# they do in the main Makefile.
#
# To change the default build target (which executes when you just type
# "make"), change the right-hand side of the definition of the "default"
# target.
#
# By default, this makefile will build the project with debugging symbols and
# without optimization. To change this, edit or remove the "-g" and "-O0"
# options in CFLAGS and LDFLAGS accordingly.
#
# By default, this makefile build the application using the GNU C compiler,
# adhering to the C99 standard with all warnings enabled.
# application-specific settings and run target
EXE=../synch
TEST=testsuite
MODS=public.o
OBJS=../mutex.o ../pingpong.o
LIBS=
UTESTOUT=utests.txt
ITESTOUT=itests.txt
default: $(TEST)
$(EXE):
make -C ../
test: utest itest
@echo "========================================"
utest: $(EXE) $(TEST)
@echo "=============================================="
@echo " UNIT TESTS"
@echo "This should take about 5 seconds"
@echo "If it is much slower or faster, your calls to"
@echo "pthread_mutex_lock and pthread_mutex_unlock"
@echo "are probably in the wrong place."
@echo ""
@echo "You can see how it works by running:"
@echo " ./tests/testsuite"
@echo "----------------------------------------------"
@./$(TEST) 2>/dev/null >$(UTESTOUT)
@cat $(UTESTOUT) | sed -n -e '/Checks/,$$p' | sed -e 's/^private.*:[EF]://g'
itest: $(EXE)
@echo "=============================================="
@echo " INTEGRATION TESTS"
@./integration.sh | tee $(ITESTOUT)
# compiler/linker settings
CC=gcc
CFLAGS=-g -O0 -Wall --std=gnu99 -pedantic
LDFLAGS=-g -O0
CFLAGS=
LIBS+=-lcheck -lm -lpthread
ifeq ($(shell uname -s),Linux)
LIBS+=-lrt -lsubunit
endif
# build targets
$(TEST): $(TEST).o $(MODS) $(OBJS)
$(CC) $(LDFLAGS) -o $(TEST) $^ $(LIBS)
%.o: %.c
$(CC) -c $(CFLAGS) $<
clean:
rm -rf $(TEST) $(TEST).o $(MODS) $(UTESTOUT) $(ITESTOUT) outputs valgrind
.PHONY: default clean test unittest inttest
@@ -0,0 +1 @@
2c9be6afe105589c6486941c344fa8af47c4f96b
@@ -0,0 +1 @@
258a022a43b06ef7cd1187fb3445760809d5af0c
@@ -0,0 +1 @@
8f29a21768d1d35aead683f394e6435fcae1edaf
@@ -0,0 +1 @@
016cd27526965203f7be5709148c6ba67a2a8cec
@@ -0,0 +1,2 @@
Running mutual exclusion test
Value of shared: 0
@@ -0,0 +1,6 @@
Running 1 iteration(s) of ping-pong
PING!
PONG!
PONG: Game over
PING: Game over
There should be 0 iterations left: 0
@@ -0,0 +1,24 @@
Running 10 iteration(s) of ping-pong
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PONG: Game over
PING: Game over
There should be 0 iterations left: 0
@@ -0,0 +1,14 @@
Running 5 iteration(s) of ping-pong
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PONG: Game over
PING: Game over
There should be 0 iterations left: 0
@@ -0,0 +1,24 @@
Running a controlled timing exercise
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PING!
PONG!
PONG: Game over
PING: Game over
Value of result should be 0: 0
+75
View File
@@ -0,0 +1,75 @@
#!/bin/bash
EXE="../synch"
function run_test {
# parameters
TAG=$1
ARGS=$2
# file paths
OUTPUT=outputs/$TAG.txt
DIFF=outputs/$TAG.diff
EXPECT=expected/$TAG.txt
VALGRND=valgrind/$TAG.txt
# print tag format
PTAG=$(printf '%-30s' "$TAG")
# check for expected text that needs to be fixed
if [ ! -z "$(egrep "<<<<.*>>>>" "$EXPECT")" ] ; then
echo "$PTAG FAIL ($EXPECT not correct)"
return
fi
# compare the file
SHAOUT=$(shasum "$EXPECT" | awk '{print $1}')
SHAEXP=$(cat "expected/.$TAG.sha")
if [ "$SHAOUT" != "$SHAEXP" ] ; then
echo "$PTAG FAIL (expected file is not correct)"
return
fi
# run test and compare output to the expected version
$EXE $ARGS 2>/dev/null >"$OUTPUT"
diff -u "$OUTPUT" "$EXPECT" >"$DIFF"
if [ -s "$DIFF" ]; then
# try alternative solution (if it exists)
EXPECT=expected/$TAG-2.txt
if [ -e "$EXPECT" ]; then
diff -u "$OUTPUT" "$EXPECT" >"$DIFF"
if [ -s "$DIFF" ]; then
echo "$PTAG FAIL (see $DIFF for details)"
else
echo "$PTAG pass"
fi
else
echo "$PTAG FAIL (see $DIFF for details)"
fi
else
echo "$PTAG pass"
fi
# run valgrind
valgrind $EXE $ARGS &>$VALGRND
}
# initialize output folders
mkdir -p outputs
mkdir -p valgrind
rm -f outputs/* valgrind/*
# run individual tests
source itests.include
# check for memory leaks
LEAK=`cat valgrind/*.txt | grep 'definitely lost' | grep -v ' 0 bytes in 0 blocks'`
if [ -z "$LEAK" ]; then
echo "No memory leak found."
else
echo "Memory leak(s) found. See files listed below for details."
grep 'definitely lost' valgrind/*.txt | grep -v ' 0 bytes in 0 blocks' | sed -e 's/:.*$//g' | sed -e 's/^/ - /g'
fi
+9
View File
@@ -0,0 +1,9 @@
# list of integration tests
# format: run_test <TAG> <ARGS>
# <TAG> used as the root for all filenames (i.e., "expected/$TAG.txt")
# <ARGS> command-line arguments to test
run_test INTEG_run_mutex "-m"
run_test INTEG_run_pingpong "-p 1"
run_test INTEG_run_pingpong_5 "-p 5"
run_test INTEG_run_pingpong_10 "-p 10"
+98
View File
@@ -0,0 +1,98 @@
#include <assert.h>
#include <check.h>
#include <inttypes.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "../mutex.h"
double time_diff (struct timeval start, struct timeval end)
{
double ending = end.tv_sec + (end.tv_usec * 0.000001);
double starting = start.tv_sec + (start.tv_usec * 0.000001);
return ending - starting;
}
START_TEST (MIN_mutex_run_two_threads)
{
printf ("======================================\n");
printf ("PUBLIC\n");
printf (" MIN mutex run two threads\n");
printf (" Call runner in two threads and ensure result is 0\n");
pthread_mutex_t lock;
pthread_mutex_init (&lock, NULL);
int64_t shared = run ();
pthread_mutex_destroy (&lock);
ck_assert_int_eq (shared, 0);
printf ("\n");
}
END_TEST
START_TEST (MIN_mutex_run_two_threads_time)
{
printf ("======================================\n");
printf ("PUBLIC\n");
printf (" MIN mutex runner two threads time\n");
printf (" Call runner in two threads and measure time\n");
printf (" Multithreaded should take more than 3 times and\n");
printf (" less than 6 times the unithreaded time.\n");
int64_t num = 0;
int64_t *shared = &num;
struct timeval start, end;
gettimeofday (&start, NULL);
for (int j = 0; j < 1000000; j++)
{
for (int i = 0; i < 100; i++)
{
*shared += 1;
*shared -= 1;
}
}
gettimeofday (&end, NULL);
double unidiff = time_diff (start, end);
pthread_mutex_t lock;
pthread_mutex_init (&lock, NULL);
gettimeofday (&start, NULL);
num = run ();
gettimeofday (&end, NULL);
double multidiff = time_diff (start, end);
printf ("\n Unithreaded time: %f\n Multithreaded time: %f\n\n",
unidiff, multidiff);
ck_assert_int_eq (num, 0);
ck_assert (unidiff * 6 > multidiff);
ck_assert (unidiff * 2.3 < multidiff);
printf ("\n");
}
END_TEST
/*
1 - Create a queue of size 1 and put things in one at a time, pausing
for 50 ms in between.
2 - Create a queue of size 8, fill it, then start the worker.
3 - Create a queue of size 15, start the listener, then pull one item
at a time.
4 - Just use fifo_queue for size 10, 20, and 30.
*/
void public_tests (Suite *s)
{
TCase *tc_public = tcase_create ("Public");
tcase_set_timeout (tc_public, 30.0);
tcase_add_test (tc_public, MIN_mutex_run_two_threads);
tcase_add_test (tc_public, MIN_mutex_run_two_threads_time);
suite_add_tcase (s, tc_public);
}
+32
View File
@@ -0,0 +1,32 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <check.h>
extern void public_tests (Suite *s);
Suite * test_suite (void)
{
Suite *s = suite_create ("Default");
public_tests (s);
return s;
}
void run_testsuite ()
{
Suite *s = test_suite ();
SRunner *sr = srunner_create (s);
srunner_run_all (sr, CK_NORMAL);
srunner_free (sr);
}
int main (void)
{
srand((unsigned)time(NULL));
run_testsuite ();
return EXIT_SUCCESS;
}