tests: add testing support and basic tests
This commit is contained in:
parent
cfd78de3e6
commit
a466a9839c
|
@ -23,6 +23,7 @@ rtdl_deps = [ ]
|
|||
headers_only = get_option('headers_only')
|
||||
no_headers = get_option('mlibc_no_headers')
|
||||
static = get_option('static')
|
||||
build_tests = get_option('build_tests')
|
||||
disable_ansi_option = false
|
||||
disable_posix_option = false
|
||||
disable_linux_option = false
|
||||
|
@ -205,7 +206,7 @@ if not headers_only
|
|||
dependencies: rtdl_deps,
|
||||
install: true)
|
||||
|
||||
shared_library('c',
|
||||
libc = shared_library('c',
|
||||
[
|
||||
libc_sources,
|
||||
internal_sources,
|
||||
|
@ -232,7 +233,7 @@ if not headers_only
|
|||
dependencies: rtdl_deps,
|
||||
install: false)
|
||||
ldso_dep = declare_dependency(link_with: ldso_lib, sources: rtdl_sources)
|
||||
static_library('c',
|
||||
libc = static_library('c',
|
||||
[
|
||||
libc_sources,
|
||||
internal_sources,
|
||||
|
@ -252,3 +253,7 @@ if not headers_only
|
|||
static_library('m', 'libm/src/dummy.cpp', install: true)
|
||||
endif
|
||||
endif
|
||||
|
||||
if build_tests
|
||||
subdir('tests/')
|
||||
endif
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
option('headers_only', type : 'boolean', value : false)
|
||||
option('mlibc_no_headers', type : 'boolean', value : false)
|
||||
option('static', type : 'boolean', value : false)
|
||||
option('build_tests', type: 'boolean', value : false)
|
||||
|
|
|
@ -29,7 +29,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt1',
|
||||
crt = custom_target('crt1',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'crt-x86_64/crt1.S',
|
||||
|
|
|
@ -35,7 +35,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt0',
|
||||
crt = custom_target('crt0',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'crt-x86_64/crt0.S',
|
||||
|
|
|
@ -28,7 +28,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt1',
|
||||
crt = custom_target('crt1',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'x86_64-crt/crt1.S',
|
||||
|
|
|
@ -70,7 +70,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt0',
|
||||
crt = custom_target('crt0',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'crt-src/crt0.S',
|
||||
|
|
|
@ -36,7 +36,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt0',
|
||||
crt = custom_target('crt0',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'crt-x86_64/crt0.S',
|
||||
|
|
|
@ -39,7 +39,7 @@ if not no_headers
|
|||
endif
|
||||
|
||||
if not headers_only
|
||||
custom_target('crt0',
|
||||
crt = custom_target('crt0',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: 'crt-src/crt0.S',
|
||||
|
|
12
tests/ansi/sprintf.c
Normal file
12
tests/ansi/sprintf.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
char buf[11];
|
||||
sprintf(buf, "%d", 12);
|
||||
assert(buf[0] == '1' && buf[1] == '2' && buf[2] == '\0');
|
||||
sprintf(buf, "%f", 3.14);
|
||||
assert(buf[0] == '3' && buf[1] == '.' && buf[2] == '1'
|
||||
&& buf[3] == '4' && buf[4] == '\0');
|
||||
return 0;
|
||||
}
|
10
tests/ansi/sscanf.c
Normal file
10
tests/ansi/sscanf.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
int x = 0;
|
||||
char buf[] = "12345";
|
||||
sscanf(buf, "%d", &x);
|
||||
assert(x == 12345);
|
||||
return 0;
|
||||
}
|
33
tests/meson.build
Normal file
33
tests/meson.build
Normal file
|
@ -0,0 +1,33 @@
|
|||
ansi_test_cases = [
|
||||
'sscanf',
|
||||
'sprintf'
|
||||
]
|
||||
|
||||
posix_test_cases = [
|
||||
'inet_ntop',
|
||||
'inet_pton'
|
||||
]
|
||||
|
||||
if not disable_ansi_option
|
||||
foreach f : ansi_test_cases
|
||||
exec = executable('ansi-' + f, ['ansi/' + f + '.c', crt],
|
||||
link_with: libc, include_directories: libc_include_dirs,
|
||||
build_rpath: meson.build_root(),
|
||||
c_args: '-no-pie',
|
||||
link_args: ['-Wl,--dynamic-linker=' + meson.build_root() + '/ld.so',
|
||||
'-no-pie'])
|
||||
test('ansi/' + f, exec)
|
||||
endforeach
|
||||
endif
|
||||
|
||||
if not disable_posix_option
|
||||
foreach f : posix_test_cases
|
||||
exec = executable('posix-' + f, ['posix/' + f + '.c', crt],
|
||||
link_with: libc, include_directories: libc_include_dirs,
|
||||
build_rpath: meson.build_root(),
|
||||
c_args: '-no-pie',
|
||||
link_args: ['-Wl,--dynamic-linker=' + meson.build_root() + '/ld.so',
|
||||
'-no-pie'])
|
||||
test('posix/' + f, exec)
|
||||
endforeach
|
||||
endif
|
14
tests/posix/inet_ntop.c
Normal file
14
tests/posix/inet_ntop.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
struct in_addr addr;
|
||||
addr.s_addr = (1 << 24) |
|
||||
(1 << 16) | (1 << 8) | 1;
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
assert(inet_ntop(AF_INET, &addr, buf, INET_ADDRSTRLEN) != NULL);
|
||||
assert(strncmp("1.1.1.1", buf, INET_ADDRSTRLEN) == 0);
|
||||
return 0;
|
||||
}
|
16
tests/posix/inet_pton.c
Normal file
16
tests/posix/inet_pton.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
struct in_addr addr;
|
||||
assert(inet_pton(AF_INET, "1.1.1.1", &addr));
|
||||
assert((addr.s_addr & 0xFF) == 1);
|
||||
assert(((addr.s_addr >> 8) & 0xFF) == 1);
|
||||
assert(((addr.s_addr >> 16) & 0xFF) == 1);
|
||||
assert(((addr.s_addr >> 24) & 0xFF) == 1);
|
||||
|
||||
assert(!inet_pton(AF_INET, "256.999.1234.555", &addr));
|
||||
assert(!inet_pton(AF_INET, "a.b.c.d", &addr));
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue