Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-platform tests #86

Merged
merged 10 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions bindings/mruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Metrics/BlockLength:
- 'Rakefile'
- 'test/**/*.rb'

Metrics/BlockNesting:
Exclude:
- 'test/printf.rb'

Security/Eval:
Exclude:
- 'test/**/*.rb'
Expand Down
8 changes: 7 additions & 1 deletion bindings/mruby/test/printf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
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
Expand Down
8 changes: 7 additions & 1 deletion bindings/ruby/spec/lib/kernaux/printf/sprintf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
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
Expand Down
2 changes: 1 addition & 1 deletion common/printf_orig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
12 changes: 12 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
####################
Expand Down
7 changes: 6 additions & 1 deletion tests/printf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
34 changes: 34 additions & 0 deletions tests/test_printf_reg.c
Original file line number Diff line number Diff line change
@@ -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);
}
}