tests: Port to modern C

Fix various tests in order to make them compatible with C99.
Part of the patches have been accepted upstream already, some are still
being reviewed.
This commit is contained in:
Frédéric Bérat 2023-02-14 15:38:11 +01:00
parent a517ed0aba
commit 12cff5a323
6 changed files with 1588 additions and 1 deletions

View File

@ -0,0 +1,31 @@
From 2a9908da9dbc075ee6c4e853cf3be0365b15f202 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= <fberat@redhat.com>
Date: Mon, 12 Dec 2022 08:05:53 +0100
Subject: [PATCH] tests: Fix 'type defaults' error in link_cond due to main not
being properly declared
This is related to an effort to prepare Automake for future GCC/Clang
versions which set c99 as default standard to be used.
Not properly declaring main as "int main(...)" is rejected since c99.
* t/link_cond.sh: Add (void) to main definition.
---
t/link_cond.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/link_cond.sh b/t/link_cond.sh
index 45d0d7f40..889623131 100644
--- a/t/link_cond.sh
+++ b/t/link_cond.sh
@@ -52,7 +52,7 @@ $AUTOCONF
rm -f *.c++
cat > less.c <<'END'
/* Valid C but deliberately invalid C++ */
-main ()
+int main (void)
{
int new = 0;
return new;
--
2.39.1

View File

@ -0,0 +1,34 @@
From 6d6fc91c472fd84bd71a1b012fa9ab77bd94efea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= <fberat@redhat.com>
Date: Mon, 12 Dec 2022 07:32:13 +0100
Subject: [PATCH] tests: depcomp: ensure make_ok() fails when run_make fails
While running automake tests with -std-gnu=c99, the compiler report
errors which lead to make to fail. Yet, these failures are ignored
during the tests, which considers them to be successful as stderror is
check for one specific pattern.
If make fails, investigation should be made to discover why, whatever
the reason for the failure is.
* t/ax/depcomp.sh: Make make_ok fail when make fails.
---
t/ax/depcomp.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/ax/depcomp.sh b/t/ax/depcomp.sh
index 3c4db10e3..7a3ac63a7 100644
--- a/t/ax/depcomp.sh
+++ b/t/ax/depcomp.sh
@@ -160,7 +160,7 @@ case $depcomp_with_libtool in
echo lib_LTLIBRARIES = libfoo.la >> Makefile.am
make_ok ()
{
- run_make -M -- ${1+"$@"}
+ run_make -M -- ${1+"$@"} || return 1
$FGREP 'unknown directive' output && return 1
rm -f output
# Checks for stray files possibly left around by less common
--
2.39.1

View File

@ -23,7 +23,7 @@ Summary: A GNU tool for automatically creating Makefiles
Name: automake
# Any bump here requires libtool rebuild, rhbz#1813010
Version: %{api_version}.5
Release: 11%{?dist}
Release: 12%{?dist}
# docs ~> GFDL, sources ~> GPLv2+, mkinstalldirs ~> PD and install-sh ~> MIT
License: GPLv2+ and GFDL and Public Domain and MIT
@ -38,6 +38,18 @@ Patch0: fort2.patch
# From upstream: ed1368e8803e8934a8bbab52a38753484dba2a37
Patch1: 0001-test-avoid-apostrophe-in-test-document.patch
# From upstream: 2a9908da9dbc075ee6c4e853cf3be0365b15f202
Patch2: 0001-tests-Fix-type-defaults-error-in-link_cond-due-to-ma.patch
# Proposed upstream: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59993#23
Patch3: v2-0002-tests-Fix-implicit-function-declaration-errors.patch
# Proposed upstream: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60962#5
Patch4: v3-0003-tests-Fix-implicit-function-declaration-in-ax-dep.patch
# Proposed upstream: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59994#29
Patch5: v2-0001-tests-Don-t-try-to-prevent-flex-to-include-unistd.patch
# From upstream: 6d6fc91c472fd84bd71a1b012fa9ab77bd94efea
# Reveals failures due to C99 porting that wouldn't be seen otherwise
Patch6: 0001-tests-depcomp-ensure-make_ok-fails-when-run_make-fai.patch
URL: http://www.gnu.org/software/automake/
Requires: autoconf >= 2.65
@ -141,6 +153,9 @@ make -k %{?_smp_mflags} check %{?TESTS_FLAGS: TESTS="%{TESTS_FLAGS}"} \
%changelog
* Tue Feb 14 2023 Frederic Berat <fberat@redhat.com> - 1.16.5-12
- Port to modern C: various fixes
* Fri Jan 20 2023 Frederic Berat <fberat@redhat.com> - 1.16.5-11
- Fix test failure due to texinfo 7.0 update

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,265 @@
From 38f4f6dcdb907e0006a8e83246e010d5d5cad98d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= <fberat@redhat.com>
Date: Thu, 8 Dec 2022 10:09:14 +0100
Subject: [PATCH v2 2/3] tests: Fix implicit function declaration errors
In-Reply-To: <20221212070554.1635775-3-fberat@redhat.com>
Changes from v1:
Modifications to "t/ax/depcomp.sh" have been moved to a dedicated patch
-- 8< --
This is related to an effort to prepare Automake for future GCC/Clang
versions which set c99 as default standard to be used.
Function should be properly declared prior to use in order to be
compatible with c99 standard.
This is valid for both local functions and standard functions (as
printf).
Modified files:
* t/c-demo.sh
* t/cond35.sh
* t/dist-vs-built-sources.sh
* t/lex-clean.sh
* t/lex-multiple.sh
* t/lex-nodist.sh
* t/ltcond2.sh
* t/ltconv.sh
* t/subobj-clean-lt-pr10697.sh
* t/subobj-clean-pr10697.sh
* t/tags-pr12372.sh
* t/yacc-basic.sh
* t/yacc-clean.sh
* t/yacc-nodist.sh
---
t/c-demo.sh | 1 +
t/cond35.sh | 2 ++
t/dist-vs-built-sources.sh | 1 +
t/lex-clean.sh | 1 +
t/lex-multiple.sh | 4 ++++
t/lex-nodist.sh | 2 ++
t/ltcond2.sh | 2 ++
t/ltconv.sh | 6 ++++++
t/subobj-clean-lt-pr10697.sh | 10 +++++++++-
t/subobj-clean-pr10697.sh | 10 +++++++++-
t/tags-pr12372.sh | 3 ++-
t/yacc-basic.sh | 1 +
t/yacc-clean.sh | 4 ++++
t/yacc-nodist.sh | 2 ++
14 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/t/c-demo.sh b/t/c-demo.sh
index 7e0e8d64f..d25bf214b 100644
--- a/t/c-demo.sh
+++ b/t/c-demo.sh
@@ -113,6 +113,7 @@ test -f build-aux/compile # We have per-target flags on C sources.
./configure --enable-dependency-tracking
cat > src/main.c << 'END'
+#include <stdio.h>
#include "foo.h"
#include "bar.h"
int main (void)
diff --git a/t/cond35.sh b/t/cond35.sh
index 215a22548..bad133970 100644
--- a/t/cond35.sh
+++ b/t/cond35.sh
@@ -73,6 +73,8 @@ END
cat > tparse.y << 'END'
%{
+extern int yylex(void);
+
void yyerror (const char *s) {}
%}
%token EOF
diff --git a/t/dist-vs-built-sources.sh b/t/dist-vs-built-sources.sh
index d038e66dd..db2776f9a 100644
--- a/t/dist-vs-built-sources.sh
+++ b/t/dist-vs-built-sources.sh
@@ -41,6 +41,7 @@ foo_SOURCES = foo.c
END
cat > foo.c << 'END'
+#include <stdio.h>
#include "h.h"
int main (void) { printf ("%s\n", F); return 0; }
END
diff --git a/t/lex-clean.sh b/t/lex-clean.sh
index 5aa199338..e53da8fd2 100644
--- a/t/lex-clean.sh
+++ b/t/lex-clean.sh
@@ -61,6 +61,7 @@ cat > lexer.l << 'END'
END
cat > main.c << 'END'
+extern int yylex (void);
int main (void)
{
return yylex ();
diff --git a/t/lex-multiple.sh b/t/lex-multiple.sh
index 2655b633e..bf119ec84 100644
--- a/t/lex-multiple.sh
+++ b/t/lex-multiple.sh
@@ -56,6 +56,10 @@ cat > main.c << 'END'
#include <stdlib.h>
#include <string.h>
+extern int yylex (void);
+extern int foolex (void);
+extern int bar_lex (void);
+
int main (int argc, char *argv[])
{
if (argc != 2)
diff --git a/t/lex-nodist.sh b/t/lex-nodist.sh
index 599539405..187dd5437 100644
--- a/t/lex-nodist.sh
+++ b/t/lex-nodist.sh
@@ -62,6 +62,8 @@ CLEANFILES = $(nodist_prog_SOURCES)
END
cat > main.c << 'END'
+extern int yylex (void);
+
int main ()
{
return yylex ();
diff --git a/t/ltcond2.sh b/t/ltcond2.sh
index 29244c9b3..7e7bcadc4 100644
--- a/t/ltcond2.sh
+++ b/t/ltcond2.sh
@@ -73,6 +73,8 @@ void print (void)
END
cat > main.c <<'END'
+extern void print(void);
+
int main (void)
{
print();
diff --git a/t/ltconv.sh b/t/ltconv.sh
index 2c4cc47a1..ec79ef80e 100644
--- a/t/ltconv.sh
+++ b/t/ltconv.sh
@@ -91,6 +91,12 @@ echo 'int sub22 () { return 22; }' > sub2/sub22/sub22.c
cat >test.c <<'EOF'
#include <stdio.h>
+
+extern int sub1 (void);
+extern int sub2 (void);
+extern int sub21 (void);
+extern int sub22 (void);
+
int main ()
{
if (1 != sub1 ())
diff --git a/t/subobj-clean-lt-pr10697.sh b/t/subobj-clean-lt-pr10697.sh
index bb656c43f..53fc02f09 100644
--- a/t/subobj-clean-lt-pr10697.sh
+++ b/t/subobj-clean-lt-pr10697.sh
@@ -83,7 +83,15 @@ libfoo_la_SOURCES = \
END
mkdir sub1 sub2
-echo 'int libmain (void)' > main.c
+
+echo "/* Subobj clean: libtool case*/" > main.c
+for i in 1 2; do
+ for j in a b c d e f; do
+ echo "extern void $j$i (void);" >> main.c
+ done
+done
+
+echo 'int libmain (void)' >> main.c
echo '{' >> main.c
for i in 1 2; do
for j in a b c d e f; do
diff --git a/t/subobj-clean-pr10697.sh b/t/subobj-clean-pr10697.sh
index f77de8c92..a7f97f6d1 100644
--- a/t/subobj-clean-pr10697.sh
+++ b/t/subobj-clean-pr10697.sh
@@ -81,7 +81,15 @@ foo_SOURCES = \
END
mkdir sub1 sub2
-echo 'int main (void)' > main.c
+
+echo "/* Subobj clean: generic case*/" > main.c
+for i in 1 2; do
+ for j in a b c d e f; do
+ echo "extern void $j$i (void);" >> main.c
+ done
+done
+
+echo 'int main (void)' >> main.c
echo '{' >> main.c
for i in 1 2; do
for j in a b c d e f; do
diff --git a/t/tags-pr12372.sh b/t/tags-pr12372.sh
index b9c022f70..1a9e1e026 100644
--- a/t/tags-pr12372.sh
+++ b/t/tags-pr12372.sh
@@ -53,7 +53,8 @@ noinst_PROGRAMS = zap
zap_SOURCES = zardoz.pc
END
-echo 'int main(void) [ return bar(1); ]' > foo-main.pc
+echo 'extern int bar(int);' > foo-main.pc
+echo 'int main(void) [ return bar(1); ]' >> foo-main.pc
echo 'int bar(int x) { return !x; }' > barbar.c
echo 'int m@in(void) { return 0; }' > sub/zardoz.pc
diff --git a/t/yacc-basic.sh b/t/yacc-basic.sh
index 5b258a30c..8cc0d06a2 100644
--- a/t/yacc-basic.sh
+++ b/t/yacc-basic.sh
@@ -49,6 +49,7 @@ a : 'a' { exit(0); };
END
cat > foo.c << 'END'
+extern int yyparse(void);
int main () { yyparse (); return 1; }
END
diff --git a/t/yacc-clean.sh b/t/yacc-clean.sh
index 373774b6a..fef079cf3 100644
--- a/t/yacc-clean.sh
+++ b/t/yacc-clean.sh
@@ -65,6 +65,8 @@ END
cat > sub1/parse.y << 'END'
%{
+#include <stdio.h>
+
int yylex () { return (getchar ()); }
void yyerror (const char *s) {}
%}
@@ -74,6 +76,8 @@ END
cp sub1/parse.y sub2/parse.y
cat > sub1/main.c << 'END'
+extern int yyparse(void);
+
int main ()
{
return yyparse ();
diff --git a/t/yacc-nodist.sh b/t/yacc-nodist.sh
index d350a80f9..4a8ebe9ca 100644
--- a/t/yacc-nodist.sh
+++ b/t/yacc-nodist.sh
@@ -78,6 +78,8 @@ BUILT_SOURCES = parse.h
END
cat > sub1/main.c << 'END'
+extern int yyparse(void);
+
int main ()
{
return yyparse ();
--
2.38.1

View File

@ -0,0 +1,58 @@
From 5e74354030fe88e038a6fc1b3f4c2321df150352 Mon Sep 17 00:00:00 2001
From: Frederic Berat <fberat@redhat.com>
Date: Fri, 16 Dec 2022 06:42:45 +0100
Subject: [PATCH v3] tests: Fix implicit function declaration in ax/depcomp.sh
In-Reply-To: <20230113064804.580F5340B54@smtp.gentoo.org>
Change since v2:
- Replace the mv operation by a cp operation to ensure that subfoo.h is
considered being modified.
-- 8< --
In depcomp.sh, the following occurs:
1. Files are created so that headers and units are available in
subdirectories
2. Multiple "make" are executed, while modifying the content of the
headers, some should fail, others should succeed.
3. At the end, the "sub/subfoo.h" header gets removed.
4. make is executed again, which is expected to succeed.
Yet, with c99, this can't work as the subfoo.h header contains
declaration that are used by foo.c.
Thus, we need to get them back, either by inserting the declaration in
foo.c (or any other header/unit), or by restoring subfoo.h to its
original state.
The later solution seems the easiest path, being less intrusive in
depcomp.sh.
---
t/ax/depcomp.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/ax/depcomp.sh b/t/ax/depcomp.sh
index 7a3ac63a7..c92f7c8df 100644
--- a/t/ax/depcomp.sh
+++ b/t/ax/depcomp.sh
@@ -243,6 +243,7 @@ cat > sub/subfoo.h <<'END'
#include <stdio.h>
extern int subfoo (void);
END
+cp sub/subfoo.h sub/subfoo.save
cat > src/baz.c <<'END'
#include "baz.h"
@@ -399,8 +400,7 @@ do_test ()
&& rewrite "$srcdir"/sub/subfoo.h echo 'choke me' \
&& not $MAKE \
&& delete "$srcdir"/sub/subfoo.h \
- && edit "$srcdir"/sub/subfoo.c -e 1d \
- && edit "$srcdir"/foo.h -e 2d \
+ && cp "$srcdir"/sub/subfoo.save "$srcdir"/sub/subfoo.h \
&& make_ok \
|| r='not ok'
result_ "$r" "$pfx dependency tracking works"
--
2.39.0