Add tests for hang

This commit is contained in:
Alex Kotov 2020-11-27 21:04:15 +05:00
parent 5ac7651c06
commit 95d81d092a
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 50 additions and 0 deletions

7
.gitignore vendored
View File

@ -19,3 +19,10 @@
/include/Makefile.in
/install-sh
/missing
/test-driver
/test-suite.log
/tests/test*.log
/tests/test*.trs
/tests/hang
/tests/test_hang_segfault

View File

@ -4,6 +4,17 @@ AM_CFLAGS = -std=c99 -I$(top_srcdir)/include
lib_LIBRARIES = libkernaux.a
TESTS = \
tests/test_hang_segfault
noinst_PROGRAMS = \
$(TESTS) \
tests/hang
libkernaux_a_SOURCES = \
src/arch/i386.S \
src/pfa.c
tests_hang_SOURCES = $(libkernaux_a_SOURCES) tests/hang.c
tests_test_hang_segfault_SOURCES = tests/test_hang_segfault.c

View File

@ -14,6 +14,8 @@ AC_CONFIG_FILES([
include/Makefile
])
PKG_CHECK_MODULES([CHECK], [check])
AC_LANG([C])
AM_PROG_AR

8
tests/hang.c Normal file
View File

@ -0,0 +1,8 @@
#include <kernaux/arch/i386.h>
int main()
{
kernaux_arch_i386_hang();
return 0;
}

View File

@ -0,0 +1,22 @@
#include <assert.h>
#include <string.h>
#include <unistd.h>
#define __USE_POSIX2
#include <stdio.h>
int main()
{
FILE *const fd = popen("tests/hang 2>&1", "r");
assert(fd != NULL);
char buffer[256];
char *const result = fgets(buffer, 256, fd);
assert(result == buffer);
assert(0 == strncmp(result, "Segmentation fault (core dumped)\n", 256));
const int status = pclose(fd);
assert(status != 0);
return 0;
}