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
+86
View File
@@ -0,0 +1,86 @@
#
# 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=../net
TEST=testsuite
MODS=public.o
OBJS=../client.o private.o
LIBS=
UTESTOUT=utests.txt
ITESTOUT=itests.txt
SCHECKOUT=style.txt
default: $(TEST)
$(EXE):
make -C ../
test: utest itest style
@echo "========================================"
utest: $(EXE) $(TEST)
@echo "========================================"
@echo " UNIT TESTS"
@./$(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)
style: $(EXE)
@echo "========================================"
@echo " CODING STYLE CHECK"
@./style.sh 2>/dev/null >$(SCHECKOUT)
@cat $(SCHECKOUT)
# 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) $(SCHECKOUT) outputs valgrind ckstyle
.PHONY: default clean test unittest inttest
@@ -0,0 +1 @@
6aa4050ebd7cf3e2973480a61c8f3e10abae0b8b
@@ -0,0 +1 @@
1954727e95f02e160a1ca5747b42de74ba7a73bb
@@ -0,0 +1 @@
9e5b32bfdef634ce9687b592ef6ab66dd2359d3e
@@ -0,0 +1 @@
16f74b0708234d24ac814851071de4a4f8d3893a
@@ -0,0 +1 @@
c0a296ad55ce3db887a3fbfa529ec4b3dc407e4a
@@ -0,0 +1 @@
fb304af0dc2a1fd9029541d8e653995755bc8b2c
+1
View File
@@ -0,0 +1 @@
ns3.jmu.edu 53: UDP IPv4 134.126.115.46
@@ -0,0 +1 @@
ns3.jmu.edu 53: UDP IPv6 ::ffff:134.126.115.46
@@ -0,0 +1 @@
ns3.jmu.edu 53: no address information
@@ -0,0 +1 @@
localhost http: TCP IPv4 127.0.0.1
@@ -0,0 +1 @@
localhost http: TCP IPv6 ::1
@@ -0,0 +1 @@
w3.cs.jmu.edu http: TCP IPv4 134.126.20.33
@@ -0,0 +1 @@
w3.cs.jmu.edu http: TCP IPv6 ::ffff:134.126.20.33
@@ -0,0 +1 @@
w3.cs.jmu.edu http: no address information
+75
View File
@@ -0,0 +1,75 @@
#!/bin/bash
EXE="../net"
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
+14
View File
@@ -0,0 +1,14 @@
# 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_localhost_ipv4 "localhost"
run_test INTEG_localhost_ipv6 "-6 localhost"
run_test INTEG_w3_ipv6 "-6 w3.cs.jmu.edu"
run_test INTEG_w3_ipv4 "w3.cs.jmu.edu"
run_test INTEG_53_ns3 "-p 53 ns3.jmu.edu"
run_test INTEG_53_ns3_ipv6 "-6 -p 53 ns3.jmu.edu"
#run_test EXTRA_youtube_H "-w / youtube.com"
#run_test EXTRA_w3_index_H "-w /index.html w3.cs.jmu.edu"
#run_test EXTRA_nope_H "-w /nope.html example.com"
Binary file not shown.
+100
View File
@@ -0,0 +1,100 @@
#include <arpa/inet.h>
#include <assert.h>
#include <check.h>
#include <fcntl.h>
#include <inttypes.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "../client.h"
START_TEST (UNIT_addr_string_localhost_v4)
{
printf ("======================================\n");
printf ("PUBLIC\n");
printf (" UNIT addr string localhost v4\n");
printf (" Convert 32-bit integer address for localhost\n");
printf (" into dotted-decimal 127.0.0.1 string format.\n\n");
struct sockaddr_in address;
memset (&address, 0, sizeof (address));
address.sin_addr.s_addr = htonl (0x7f000001);
struct addrinfo server;
server.ai_family = AF_INET;
server.ai_addr = (struct sockaddr *) &address;
char *ipv4 = addr_string (&server);
printf (" IPv4 address for localhost is '%s'\n", ipv4);
printf ("\n");
ck_assert_str_eq (ipv4, "127.0.0.1");
free (ipv4);
}
END_TEST
START_TEST (UNIT_get_server_list_localhost)
{
printf ("======================================\n");
printf ("PUBLIC\n");
printf (" UNIT get server list localhost\n");
printf (" Use getaddrinfo() to gather information about localhost\n");
printf (" for the HTTP protocol with IPv4. Requires network access\n");
printf (" to get information from DNS.\n\n");
struct addrinfo *server =
get_server_list ("localhost", "http", true, false);
struct sockaddr_in *addr4 = (struct sockaddr_in *) server->ai_addr;
uint32_t address = ntohl (addr4->sin_addr.s_addr);
printf (" IPv4 address for localhost is 0x%08" PRIx32 "\n", address);
printf ("\n");
ck_assert_int_eq (address, 0x7f000001);
freeaddrinfo (server);
}
END_TEST
START_TEST (UNIT_serv_string_localhost)
{
printf ("======================================\n");
printf ("PUBLIC\n");
printf (" UNIT serv string localhost\n");
printf (" Converts a struct addrinfo into a string that contains\n");
printf (" the transport-layer protocol, IP version, and IP address\n");
printf (" in the appropriate format.\n\n");
struct sockaddr_in address;
memset (&address, 0, sizeof (address));
address.sin_addr.s_addr = htonl (0x7f000001);
struct addrinfo server;
server.ai_family = AF_INET;
server.ai_addr = (struct sockaddr *) &address;
server.ai_socktype = SOCK_STREAM;
char *serv_info = serv_string (&server);
printf (" Server information for localhost: '%s'\n", serv_info);
printf ("\n");
ck_assert_str_eq (serv_info, "TCP IPv4 127.0.0.1");
free (serv_info);
}
END_TEST
void public_tests (Suite *s)
{
TCase *tc_public = tcase_create ("Public");
tcase_add_test (tc_public, UNIT_addr_string_localhost_v4);
tcase_add_test (tc_public, UNIT_get_server_list_localhost);
tcase_add_test (tc_public, UNIT_serv_string_localhost);
suite_add_tcase (s, tc_public);
}
+53
View File
@@ -0,0 +1,53 @@
#!/bin/bash
STYLE="gnu"
IGNORE=()
FAIL=0
function comp_file {
SRC=$1
SRC_NAME=$2
# file paths
FORMAT=ckstyle/${SRC_NAME}.$STYLE
DIFF=ckstyle/${SRC_NAME}.diff
# run clang-format and compare results
clang-format --style=$STYLE $source > $FORMAT
diff -u $SRC $FORMAT >$DIFF
PTAG=$(printf '%-30s' "$SRC_NAME")
if [ -s $DIFF ]; then
echo "$PTAG FAIL (see $DIFF for details)"
FAIL=1
else
echo "$PTAG pass"
rm $DIFF
fi
rm $FORMAT
}
mkdir -p ckstyle
rm -f ckstyle/*
for source in $(ls ../*.c ../*.h) ; do
SKIP=0
src=$(basename $source)
for ignore in ${IGNORE[*]} ; do
if [ "$src" = "$ignore" ] ; then
SKIP=1
fi
done
if [ $SKIP = 0 ] ; then
comp_file $source $src
fi
done
if [ $FAIL != 0 ] ; then
echo "Code that does not adhere to GNU standards will not be accepted."
echo "You must fix these files before submission."
else
echo "Code correctly adheres to required style."
fi
+34
View File
@@ -0,0 +1,34 @@
#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);
extern void private_tests (Suite *s);
Suite * test_suite (void)
{
Suite *s = suite_create ("Default");
public_tests (s);
private_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;
}