mirror of
https://github.com/tailix/libkernaux.git
synced 2025-04-14 17:32:55 -04:00
Cross-platform tests (#86)
This commit is contained in:
parent
a904d7cf8e
commit
a0517fb9dd
10 changed files with 95 additions and 6 deletions
23
.github/workflows/main.yml
vendored
23
.github/workflows/main.yml
vendored
|
@ -29,6 +29,29 @@ jobs:
|
|||
- name: install
|
||||
run: sudo make install
|
||||
|
||||
cross:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
cross:
|
||||
- host: 'i386-unknown-elf'
|
||||
apt: 'crossbuild-essential-i386'
|
||||
cprefix: 'i686-linux-gnu-'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: dependencies
|
||||
run: sudo apt-get --yes install ${{matrix.cross.apt}}
|
||||
- name: autogen
|
||||
run: ./autogen.sh
|
||||
- name: configure
|
||||
run: ./configure --host='${{matrix.cross.host}}' --enable-tests --enable-tests-python AR='${{matrix.cross.cprefix}}ar' CC='${{matrix.cross.cprefix}}gcc' LD='${{matrix.cross.cprefix}}ld' RANLIB='${{matrix.cross.cprefix}}ranlib'
|
||||
- name: make
|
||||
run: make
|
||||
- name: check
|
||||
run: make check || (./test-suite-log && false)
|
||||
- name: install
|
||||
run: sudo make install
|
||||
|
||||
cond:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -147,4 +147,5 @@
|
|||
/tests/test_printf_fmt_gen.c
|
||||
/tests/test_printf_gen
|
||||
/tests/test_printf_gen.c
|
||||
/tests/test_printf_reg
|
||||
/tests/test_units_human
|
||||
|
|
|
@ -25,6 +25,10 @@ Metrics/BlockLength:
|
|||
- 'Rakefile'
|
||||
- 'test/**/*.rb'
|
||||
|
||||
Metrics/BlockNesting:
|
||||
Exclude:
|
||||
- 'test/printf.rb'
|
||||
|
||||
Security/Eval:
|
||||
Exclude:
|
||||
- 'test/**/*.rb'
|
||||
|
|
|
@ -56,7 +56,13 @@ if KernAux::Version.with_printf?
|
|||
else
|
||||
arg.map do |item|
|
||||
if item.is_a? Array
|
||||
item[0]
|
||||
if item.length == 1
|
||||
item[0]
|
||||
elsif item[0] == 'long long'
|
||||
item[1]
|
||||
else
|
||||
raise "Unknown format: #{args.inspect}"
|
||||
end
|
||||
else
|
||||
item
|
||||
end
|
||||
|
|
|
@ -36,7 +36,13 @@ KernAux::Version.with_printf? and RSpec.describe KernAux, '.sprintf' do
|
|||
else
|
||||
arg.map do |item|
|
||||
if item.is_a? Array
|
||||
item[0]
|
||||
if item.length == 1
|
||||
item[0]
|
||||
elsif item[0] == 'long long'
|
||||
item[1]
|
||||
else
|
||||
raise "Unknown format: #{args.inspect}"
|
||||
end
|
||||
else
|
||||
item
|
||||
end
|
||||
|
|
|
@ -196,7 +196,7 @@
|
|||
- result: '0'
|
||||
args: [['%#.1x', 0]]
|
||||
- result: ''
|
||||
args: [['%#.0llx', 0]]
|
||||
args: [['%#.0llx', ['long long', 0]]]
|
||||
- result: '0x0000614e'
|
||||
args: [['%#.8x', 0x614e]]
|
||||
- result: '0b110'
|
||||
|
|
|
@ -151,8 +151,6 @@ AS_IF([test "$with_libc" = yes], [with_libc=yes], [with_libc
|
|||
# Test args #
|
||||
#############
|
||||
|
||||
AS_IF([test "$enable_tests" = yes -a "$host_cpu" != "$build_cpu" ], AC_MSG_ERROR([can not build cross-platform tests]))
|
||||
AS_IF([test "$enable_tests_python" = yes -a "$host_cpu" != "$build_cpu" ], AC_MSG_ERROR([can not build cross-platform tests]))
|
||||
AS_IF([test "$enable_tests" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests]))
|
||||
AS_IF([test "$enable_tests_python" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests]))
|
||||
AS_IF([test "$enable_tests" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests]))
|
||||
|
|
|
@ -335,6 +335,18 @@ CLEANFILES += test_printf_gen.c
|
|||
test_printf_gen.c: printf_gen.py printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml
|
||||
python3 printf_gen.py
|
||||
|
||||
###################
|
||||
# test_printf_reg #
|
||||
###################
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += test_printf_reg
|
||||
test_printf_reg_LDADD = $(top_builddir)/libkernaux.la
|
||||
test_printf_reg_SOURCES = \
|
||||
main.c \
|
||||
test_printf_reg.c
|
||||
endif
|
||||
|
||||
####################
|
||||
# test_units_human #
|
||||
####################
|
||||
|
|
|
@ -65,7 +65,12 @@ def values(args):
|
|||
if type(arg[1]) is str:
|
||||
values += ', ' + escape_str(arg[1])
|
||||
elif type(arg[1]) is list:
|
||||
values += ', ' + escape_char(arg[1][0])
|
||||
if len(arg[1]) == 1:
|
||||
values += ', ' + escape_char(arg[1][0])
|
||||
elif arg[1][0] == 'long long':
|
||||
values += ', (long long)' + str(arg[1][1])
|
||||
else:
|
||||
raise RuntimeError('unknown format: ' + str(args))
|
||||
else:
|
||||
values += ', ' + str(arg[1])
|
||||
|
||||
|
|
34
tests/test_printf_reg.c
Normal file
34
tests/test_printf_reg.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/printf.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void test_main()
|
||||
{
|
||||
char buffer[1000];
|
||||
|
||||
// Sanity check
|
||||
{
|
||||
memset(buffer, 0xff, sizeof(buffer));
|
||||
const int result =
|
||||
kernaux_snprintf(buffer, sizeof(buffer), "%s", "Hello, World!");
|
||||
fprintf(stderr, "%d:%s\n", result, buffer);
|
||||
assert(result == 13);
|
||||
assert(strcmp(buffer, "Hello, World!") == 0);
|
||||
}
|
||||
|
||||
// i386 requires "(long long)0" instead of just "0"
|
||||
{
|
||||
memset(buffer, 0xff, sizeof(buffer));
|
||||
const int result =
|
||||
kernaux_snprintf(buffer, sizeof(buffer), "%#.0llx", (long long)0);
|
||||
fprintf(stderr, "%d:%s\n", result, buffer);
|
||||
assert(result == 0);
|
||||
assert(strcmp(buffer, "") == 0);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue