Skip to content

Commit

Permalink
Merge pull request #88 from fgont/add-unit-tests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
fgont authored Oct 16, 2024
2 parents ea79c09 + 8971495 commit 64db67b
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 97 deletions.
95 changes: 0 additions & 95 deletions .github/workflows/build-test.yml

This file was deleted.

109 changes: 109 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Build, installation, and unit tests

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
UbuntuLatest:
name: Test on Ubuntu-latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install -y libpcap-dev
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

Ubuntu2204:
name: Test on Ubuntu 22.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install -y libpcap-dev
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

Ubuntu2004:
name: Test on Ubuntu 20.04
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install -y libpcap-dev
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

MacOSLatest:
name: Test on MacOS-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
brew update
brew install libpcap
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

MacOS14:
name: Test on MacOS 14
runs-on: macos-14

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
brew update
brew install libpcap
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

MacOS13:
name: Test on MacOS 13
runs-on: macos-13

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
brew update
brew install libpcap
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests

MacOS12:
name: Test on MacOS Monterey 12
runs-on: macos-12

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
brew update
brew install libpcap
- name: Build and install tools
run: make install
- name: Unit tests
run: make unit_tests
11 changes: 10 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ DATAPATH= $(DESTDIR)$(PREFIX)/share/ipv6toolkit
BINPATH= $(DESTDIR)$(PREFIX)/bin
SBINPATH= $(DESTDIR)$(PREFIX)/sbin
SRCPATH= tools
TESTSPATH= tests


SBINTOOLS= blackhole6 flow6 frag6 icmp6 jumbo6 messi mldq6 na6 ni6 ns6 path6 ra6 rd6 rs6 scan6 script6 tcp6 udp6
BINTOOLS= addr6
TOOLS= $(BINTOOLS) $(SBINTOOLS)
TESTS= tests_libipv6
LIBS= libipv6.o

all: $(TOOLS) data/ipv6toolkit.conf
Expand Down Expand Up @@ -106,6 +108,11 @@ scan6: $(SRCPATH)/scan6.c $(SRCPATH)/scan6.h $(SRCPATH)/ipv6toolkit.h $(LIBS) $(
script6: $(SRCPATH)/script6
cp $(SRCPATH)/script6 ./

tests: $(TESTS)

tests_libipv6: $(TESTSPATH)/tests_libipv6.c libipv6.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o tests_libipv6 $(TESTSPATH)/tests_libipv6.c $(LIBS) $(LDFLAGS)

tcp6: $(SRCPATH)/tcp6.c $(SRCPATH)/tcp6.h $(SRCPATH)/ipv6toolkit.h $(LIBS) $(SRCPATH)/libipv6.h
$(CC) $(CPPFLAGS) $(CFLAGS) -o tcp6 $(SRCPATH)/tcp6.c $(LIBS) $(LDFLAGS)

Expand Down Expand Up @@ -140,7 +147,7 @@ data/ipv6toolkit.conf:
data/ipv6toolkit.conf

clean:
rm -f $(TOOLS) $(LIBS)
rm -f $(TOOLS) $(LIBS) $(TESTS)
rm -f data/ipv6toolkit.conf

install: all
Expand Down Expand Up @@ -326,3 +333,5 @@ uninstall:
rm -f $(MANPATH)/man5/ipv6toolkit.conf.5
rm -f $(MANPATH)/man7/ipv6toolkit.7

unit_tests: tests
./tests_libipv6
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ DATAPATH= $(DESTDIR)$(PREFIX)/share/ipv6toolkit
BINPATH= $(DESTDIR)$(PREFIX)/bin
SBINPATH= $(DESTDIR)$(PREFIX)/sbin
SRCPATH= tools
TESTSPATH= tests


SBINTOOLS= blackhole6 flow6 frag6 icmp6 jumbo6 messi mldq6 na6 ni6 ns6 path6 ra6 rd6 rs6 scan6 script6 tcp6 udp6
BINTOOLS= addr6
TOOLS= $(BINTOOLS) $(SBINTOOLS)
TESTS= tests_libipv6
LIBS= libipv6.o

all: $(TOOLS) data/ipv6toolkit.conf
Expand Down Expand Up @@ -102,6 +104,11 @@ script6: $(SRCPATH)/script6
tcp6: $(SRCPATH)/tcp6.c $(SRCPATH)/tcp6.h $(SRCPATH)/ipv6toolkit.h $(LIBS) $(SRCPATH)/libipv6.h
$(CC) $(CPPFLAGS) $(CFLAGS) -o tcp6 $(SRCPATH)/tcp6.c $(LIBS) $(LDFLAGS)

tests: $(TESTS)

tests_libipv6: $(TESTSPATH)/tests_libipv6.c libipv6.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o tests_libipv6 $(TESTSPATH)/tests_libipv6.c $(LIBS) $(LDFLAGS)

udp6: $(SRCPATH)/udp6.c $(SRCPATH)/udp6.h $(SRCPATH)/ipv6toolkit.h $(LIBS) $(SRCPATH)/libipv6.h
$(CC) $(CPPFLAGS) $(CFLAGS) -o udp6 $(SRCPATH)/udp6.c $(LIBS) $(LDFLAGS)

Expand Down Expand Up @@ -133,7 +140,7 @@ data/ipv6toolkit.conf:
data/ipv6toolkit.conf

clean:
rm -f $(TOOLS) $(LIBS)
rm -f $(TOOLS) $(LIBS) $(TESTS)
rm -f data/ipv6toolkit.conf

install: all
Expand Down Expand Up @@ -234,3 +241,5 @@ uninstall:
rm -f $(MANPATH)/man5/ipv6toolkit.conf.5
rm -f $(MANPATH)/man7/ipv6toolkit.7

unit_tests: tests
./tests_libipv6
16 changes: 16 additions & 0 deletions tests/tests_libipv6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <assert.h>
#include <stdlib.h>
#include "../tools/libipv6.h"

void test_is_service_port(void);

int main(void){
test_is_service_port();
exit(EXIT_SUCCESS);
}

void test_is_service_port(void){
assert(is_service_port(443));
assert(is_service_port(1000) == FALSE);
return;
}

0 comments on commit 64db67b

Please sign in to comment.