Skip to content
This repository was archived by the owner on Feb 4, 2024. It is now read-only.

Commit 0d5c037

Browse files
committed
test: Add simple build tests
Add tests to verify that picocom builds and runs without any glaring errors.
1 parent fe471bc commit 0d5c037

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

.github/workflows/smoketest.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Smoke tests
2+
on:
3+
pull_request:
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
build-and-test:
10+
strategy:
11+
matrix:
12+
distro: [fedora, ubuntu]
13+
name: Build and test
14+
runs-on: ubuntu-latest
15+
container:
16+
image: ghcr.io/picocom-ng/picocom-builder-${{ matrix.distro }}:main
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- name: Build
22+
run: |
23+
make
24+
25+
- name: Run tests
26+
run: |
27+
make smoketest

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ realclean: distclean
102102
rm -f picocom.1.html
103103
rm -f picocom.1.pdf
104104
rm -f CHANGES
105+
106+
smoketest: picocom
107+
bats tests/smoke
108+

tests/smoke/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
These are quick tests to validate that Picocom builds and runs without any errors.

tests/smoke/build.bats

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
setup() {
2+
BATS_TMPDIR="$(mktemp -d batsXXXXXX)"
3+
gcc -o "${BATS_TMPDIR}/fakeserial" tests/smoke/fakeserial.c
4+
read ptyname ptypid < <("${BATS_TMPDIR}/fakeserial")
5+
}
6+
7+
@test "picocom builds successfully" {
8+
make realclean all
9+
}
10+
11+
@test "picocom runs --help successfully" {
12+
./picocom --help
13+
}
14+
15+
@test "picocom runs --exit successfully" {
16+
timeout 5 ./picocom --exit $ptyname > "${BATS_TMPDIR}/log"
17+
res=$?
18+
(( $res == 0 ))
19+
grep "Terminal ready" "${BATS_TMPDIR}/log"
20+
}
21+
22+
teardown() {
23+
kill $ptypid
24+
rm -rf "${BATS_TMPDIR}"
25+
}

tests/smoke/fakeserial.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <unistd.h>
4+
#include <pty.h>
5+
#include <limits.h>
6+
#include <errno.h>
7+
#include <string.h>
8+
9+
int main(int argc, char *argv[]) {
10+
int porta, portb;
11+
char ptyname[PATH_MAX];
12+
pid_t pid;
13+
14+
if (openpty(&porta, &portb, ptyname, NULL, NULL) != 0) {
15+
fprintf(stderr, "ERROR: failed to open pty (%d): %s\n", errno, strerror(errno));
16+
exit(1);
17+
}
18+
19+
switch(pid = fork()) {
20+
case -1:
21+
fprintf(stderr, "ERROR: failed to start background process (%d): %s", errno, strerror(errno));
22+
exit(1);
23+
break;
24+
case 0:
25+
pause();
26+
exit(0);
27+
break;
28+
29+
default:
30+
close(porta);
31+
close(portb);
32+
break;
33+
}
34+
35+
printf("%s %d\n", ptyname, pid);
36+
return 0;
37+
}

0 commit comments

Comments
 (0)