Commit Graph

4832 Commits

Author SHA1 Message Date
rillig
bc7ef38ff0 tests/lint: add test for 'dubious operation on enum' [241] 2021-02-27 14:54:55 +00:00
rillig
88e93ce52b tests/lint: add more tests for enum mismatch 2021-02-27 13:43:36 +00:00
christos
d2bbb37090 Adjust for conditional NLS 2021-02-25 22:37:36 +00:00
rillig
2632d6d7a1 tests/libcurses: add test for '\b' in addch
Just to ensure that addch and addstr behave the same, after the recent
fix for handling '\t'.
2021-02-25 01:07:43 +00:00
rillig
e9c1f91ac6 tests/libcurses: use common style for parse error messages 2021-02-25 00:50:10 +00:00
rillig
fecd441893 tests/libcurses: use common syntax for accessing array elements
Writing *(p+1) is needlessly confusing, even though it adds a little
symmetry between *p and *(p+1).  Still, one of these expressions has
parentheses, the other doesn't, which breaks the symmetry.

Wrap overly long code line.

It's confusing to refer to the digits after the backslash once with
index 0 to 2, and the other time with index 1 to 3.
2021-02-25 00:42:00 +00:00
rillig
fede2462fc tests/libcurses: reduce indentation
No functional change.
2021-02-25 00:32:44 +00:00
rillig
91f6e103ad libcurses: ensure that '\b' in handled correctly in addstr
Just to ensure that the recent fix for '\t' handling in addstr/addch
didn't introduce another bug.
2021-02-25 00:26:57 +00:00
rillig
166112aa2a libcurses: prevent unknown escpae sequences in tests
Before, '\b' was interpreted as a simple 'b', which is confusing for C
programmers.  Same for '\a'.  There is absolutely no reason to escape
letters, so fail early in these cases.

The '\h' in the test addchstr was obviously a typo that was easy to
detect, if only the compiler had been strict enough from the very
beginning.

The code is wider than 80 characters, same as the code that parses octal
escape sequences a few lines above it.  This code will be refactored to
use less indentation in a follow-up commit.
2021-02-25 00:25:31 +00:00
christos
0cd1e61982 remove casts 2021-02-24 18:18:53 +00:00
christos
5e019a0a0d minimal fix to match the library code (really make the constants unsigned
instead)
2021-02-24 02:33:56 +00:00
christos
3ab762d4ac Will be fixed with regex update 2021-02-23 21:09:14 +00:00
christos
8621598a26 Add REG_GNU 2021-02-23 17:13:44 +00:00
christos
e78273b60d Add support for ENOSYS (was never set) 2021-02-23 16:00:37 +00:00
christos
3d2aab1347 Add REG_POSIX, and make compile on linux where we don't have a lot of the
internal flags.
2021-02-23 15:00:01 +00:00
christos
df5681bdd2 Delete category stuff that has changed with the new regex; make compile
on linux and with TRE
2021-02-23 14:59:09 +00:00
christos
cd73f43310 Comment out tests that the new stricter regex does not like 2021-02-23 14:57:16 +00:00
rillig
199346cc31 lint: change spelling of initialisation to initialization
That's the wording from the ISO C99 standard.
2021-02-22 15:09:50 +00:00
rillig
352df404f7 indent: add test demonstrating that indent cannot handle C99
indent cannot handle line-end comments.

The indent test suite requires each test file to have both a NetBSD and
a FreeBSD RCS ID.  If the FreeBSD RCS ID is missing, the test will
silently pass since in that case, an empty file is compared with an
empty file.  See the /start/,/end/ operator in t_indent.sh.
2021-02-21 21:26:26 +00:00
rillig
0826316a44 lint: add test for bit-field initialisation in traditional C 2021-02-21 14:49:23 +00:00
rillig
4bbce6e96b lint: add debug logging for initializing an array of unknown size
It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics.  The current test suite does not cover
such a case.  Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.
2021-02-21 14:19:27 +00:00
rillig
43a6794406 lint: add test for initializing a character array using a string
The previous attempt took another code path than expected.  The
initialization of static_duration actually calls initstack_string.
2021-02-21 13:10:57 +00:00
rillig
6a0956331d lint: add more tests for C99 initialization 2021-02-21 12:49:05 +00:00
rillig
4c4ccffbb5 lint: add type information to message about enum mismatch 2021-02-21 10:28:32 +00:00
rillig
c6411a2f09 lint: add test for enum mismatch in initialization
This warning is currently not user-friendly because it omits any type
information, but that information is crucial.
2021-02-21 10:12:29 +00:00
rillig
1214ba323a lint: add another test case for initializing an object 2021-02-21 09:19:53 +00:00
rillig
ab7cfcc59b lint: fix wrong warning about main falling off the bottom in C99 mode
This gets lint a small step closer to implementing C99.
2021-02-21 09:17:55 +00:00
rillig
7eea542cc1 lint: force each test to declare the expected diagnostics
By listing the expected diagnostics directly at the code that triggers
the diagnostics, it is easier to cross-check whether the diagnostics
make sense.

No functional change to lint itself.
2021-02-21 09:07:58 +00:00
rillig
331de0363e lint: add another test for C99 initializers 2021-02-21 08:05:51 +00:00
rillig
e83db15a89 lint: clean up some of the C99 tests
Several C99 tests do not actually test C99 features but instead GCC
features.  All these tests should be double-checked again.

In some other tests, split the initializers into more lines, which makes
it easier to read the debug log corresponding to these tests.  This will
be necessary for reworking the initializer code to actually conform to
C99.
2021-02-20 22:31:20 +00:00
rillig
cc8ff9b7e7 lint: ensure that '# line' directives in tests are correct
It's too easy to forget one of them when adding or removing some lines.
This would make it more difficult to locate the lines referenced in the
error messages.
2021-02-20 22:18:32 +00:00
rillig
d4c07c2ea4 lint: do not warn about 'do { ... } while (false)' in strict bool mode 2021-02-20 18:55:10 +00:00
rillig
2ed239de2f lint: add test for 'do { ... } while (false)' in strict bool mode
Right now, this variant of the popular macro pattern is flagged as
needing a /*CONSTCOND*/ annotation.  As with 'do { ... } while (0)',
there is nothing wrong with this pattern, therefore there should be no
warning.
2021-02-20 18:52:58 +00:00
rillig
9c7ebc631b lint: enable heuristics in test for strict bool mode
This is a preparation for allowing 'do { ... } while (false)', in
addition to the commonly used 'do { ... } while (0)', without declaring
the controlling expression /*CONSTCOND*/.
2021-02-20 18:49:26 +00:00
rillig
59c3c702bb lint: add test for using a bool as array index in strict bool mode 2021-02-20 18:02:58 +00:00
rillig
c76961adb2 lint: add machine-readable expectations to test for initializer 2021-02-20 16:55:32 +00:00
rillig
2a03f024cd lint: fix typo in test for pop_member
The leader of a city should rather be a mayor than a major.
2021-02-20 16:51:18 +00:00
rillig
6e51f5af89 lint: reproduce the crash from ckgetopt.c 1.2
The intention of the getopt check was to analyze only those while loops
whose condition consists of the usual getopt call.  For all other while
loops, ck.while_level was intended to stay at 0.

This was not the case in ckgetopt.c 1.2 and has been fixed in ckgetopt.c
1.3.  The code did not document the intended invariants though, which it
should have done.  This will be done in a follow-up commit.
2021-02-20 09:40:42 +00:00
nia
ada1367bac patch(1): add test cases for various backup file formats 2021-02-20 08:59:24 +00:00
martin
2916a307c1 PR kern/55272: do not skip this test on single cpu machines - it is not
the only test causing the watchdog starvation and we better find and
fix the real issue.
2021-02-19 18:36:50 +00:00
rillig
746e9c89cf lint: warn about mismatch in getopt handling 2021-02-19 12:28:56 +00:00
kre
6974a2b259 PR bin/55979
Add a sh ATF test to demonstrate a bug in the way that \0 characters
are dropped from scripts.   This test will eventually be extended to
test other potential sh script input related issues.

When initially committed, this test should fail.  It should succeed
when the fix for the PR is committed (soon).

Nb: this tests only the \0 related issues from the PR, the MSAN
detected uninitialised variable (struct field) can only be detected
by MSAN, as it has no visible impact on the operation of the shell
when running on any real (or even emulated) hardware.
(It will, however, also be fixed).
2021-02-16 09:46:24 +00:00
joerg
dd4f4a95ae Simplify to avoid copy based on the size of the source. 2021-02-15 15:55:50 +00:00
rillig
2944115b18 tests/lint: fix comments in test for message 124 2021-02-15 07:18:20 +00:00
rillig
65e35d76dc tests/libcurses: fix error handling for non-system errors
These errors are unrelated to errno.  The scanf family of functions also
does not set errno.
2021-02-15 07:06:27 +00:00
rillig
f6084dc243 tests/libcurses: document the history about tab bugs in addch/addstr
Verified by installing all versions of libcurses from 2012 to 2021 and
running a simple test program on them:

	#include <stdio.h>
	#include <curses.h>

	int
	main(int argc, char **argv)
	{
		int xstr, ystr, xch, ych;

		initscr();

		addstr("\t");
		xstr = getcurx(stdscr);
		addstr("\n");
		ystr = getcury(stdscr);

		addch('\t');
		xch = getcurx(stdscr);
		addch('\n');
		ych = getcury(stdscr);

		endwin();

		fprintf(stderr, "%s\t%d,%d\t%d,%d\n",
		    argv[1], ystr, xstr, ych, xch);
	}

Some selected outputs:

	...
	2016.11.24.14.49.08	1,0	2,8
	2016.11.28.18.25.26     1,8	2,8
	...
	2019.05.12.02.29.00	1,8	2,8
	2019.05.20.22.17.41	1,8	2,16
	...
	2021.02.13.10.37.00	1,8	2,16
	2021.02.13.14.30.37	1,8	2,8
2021-02-14 11:21:37 +00:00
joerg
0cf30132cd Adjust test cases to hit the fudge case after the changes in nbperf
itself.
2021-02-14 01:27:33 +00:00
rillig
1131246067 tests/libcurses: note that addbytes is not part of the API
https://mail-index.netbsd.org/source-changes-d/2021/02/13/msg013199.html
2021-02-13 22:19:47 +00:00
rillig
73417462e0 tests/libcurses: protect against short writes
The previous code only errored out if a write failed completely.  If it
was partially written, the program continued without writing the rest of
it.

Extract the common code into a few functions that write raw data to the
parent process.
2021-02-13 19:23:11 +00:00
rillig
9966483c8a tests/libcurses: remove unused code in linter 2021-02-13 18:24:11 +00:00
rillig
f48ee0a965 tests/libcurses: use ASCII only in terminfo description 2021-02-13 16:43:12 +00:00
rillig
c12d26a726 tests/libcurses: split terminfo entry over more lines
This provides space to see each capability on its own, instead of having
to search them in the blob of text.
2021-02-13 16:38:02 +00:00
rillig
609d11bc47 libcurses: fix wrong tab width for addch
In sysinst, the installation screen is indented with tabs.  Sysinst uses
msgc, which brings its own text layout engine.  This engine does not use
addbytes but addch.  In addch, the x position for each tab was advanced
twice as much as needed.  The menu items were thus not indented by 8
spaces but by 16, which caused an ugly line break in the German
translation.

This bug largely went unnoticed because most other applications use
addbytes instead, which worked fine all the time.  It had been
introduced somewhere between NetBSD 8.0 and NetBSD 9.0.

The code around this bug used aliased variables for win->curx and
win->cury a lot.  Getting this right is difficult and needs a thorough
test suite.  Even though libcurses has 201 tests, that is not nearly
enough to cover all the relations between the various functions in
libcurses that call each other, crossing API boundaries from internal
to external, doing character conversions on the way and juggling around
4 different types of characters (char, wchar_t, chtype, cchar_t).

The simplest fix was to remove all this aliasing, while keeping the
API the same.  If _cursesi_waddbytes is not considered part of the API,
it would be possible to replace px with win->curx in all places, same
for py and win->cury.

The complicated code with the aliasing may have been meant for
performance reasons, but it's hard to see any advantage if both points
of truth need to be synchronized all the time.

Libcurses can be built in 2 modes: with wide character support or
without (-DDISABLE_WCHAR).  The test suite only covers the variant with
wide characters.  The single-byte variant has to be tested manually.
Running sysinst with the single-byte libcurses produces the correct
layout.
2021-02-13 14:30:37 +00:00
rillig
86536876fb tests/libcurses: extract read_command_argument from process_commands
Having code indented so far to the right that each word gets its own
line is ridiculous.  Fix that.

While here, remove the cargo-cult realloc pattern, which is not needed
if the process exits immediately on error.

While here, reduce the indentation of the code by returning early.

No functional change.
2021-02-13 10:03:49 +00:00
rillig
78dd027b59 tests/libcurses: fix reading from the parent process
In case of a short read, processing the incomplete data invoked
undefined behavior.
2021-02-13 09:28:27 +00:00
rillig
2eec569208 tests/libcurses: fix child process handling
The child process needs to be properly controlled by the parent process.
Otherwise it is not possible to get code coverage data from it using
gcov since that requires the child process to exit normally.  Previously
the child process had been killed because its parent had exited.
2021-02-13 09:18:12 +00:00
rillig
2d435e1f5f tests/libcurses: fix error messages 2021-02-13 08:43:03 +00:00
rillig
c671531bee tests/libcurses: "fix" test mvwin
The test mvwin previously expected an endless stream of bytes, by
comparing the actual output with /dev/zero.  This didn't make sense as
the curses output does not contain '\0' in any of the test cases.

Compare with /dev/null instead.  This is as wrong as before, but the
curses test framework currently ignores this situation, as for many
other test cases.  See the numerous "Excess" messages in atf-run.log.
2021-02-13 08:37:21 +00:00
rillig
08813b709b tests/libcurses: remove undocumented, unused command line option
The option -T has the same effect as the removed option -p.
2021-02-13 08:26:12 +00:00
rillig
dcdcb866a3 tests/libcurses: remove include path from usage message
The option has been removed a few minutes ago.
2021-02-13 08:22:34 +00:00
rillig
177fdb97a1 tests/libcurses: clean up remaining include guard, comments
No functional change.
2021-02-13 08:17:15 +00:00
rillig
cf012ad48f tests/libcurses: clean up inclusion guards, function declarations
No functional change.
2021-02-13 08:14:46 +00:00
rillig
dfef510f35 tests/libcurses: remove include path handling
All include commands in the current test suite use relative paths.
Instead of a fixed include path, interpret the included filename
relative to the including file.
2021-02-13 08:00:07 +00:00
rillig
8e1e8b7233 tests/libcurses: align comments 2021-02-13 07:32:19 +00:00
rillig
c8713e3dc5 tests/libcurses: fix misleading usage documentation
The check-files are not config files.
2021-02-13 07:31:07 +00:00
rillig
1b4c237756 tests/libcurses: fix pipe handling in the parent process
The parent process, like the child process, needs only 2 of the 4 pipe
ends.

In verbose mode (now at testlang_parse.y:1151 and :1154), both ends of the
pipe_from_slave were examined.  This looked like a typo and has been fixed
to those pipe ends that are relevant to the parent process.
2021-02-13 07:08:45 +00:00
rillig
26ce28a5a0 tests/libcurses: fix pipe handling in child process
The child process only ever needs 2 ends of the pipes: one for reading
the commands, one for writing back the results.
2021-02-13 06:45:42 +00:00
rillig
ff6217c297 tests/libcurses: add test for addbytes 2021-02-13 06:29:45 +00:00
rillig
2f4dbca7fd tests/libcurses: fix warnings for missing environment variables 2021-02-13 05:38:16 +00:00
rillig
ef1df6f9cf tests/libcurses: format misleading do-while loop 2021-02-12 21:29:54 +00:00
rillig
18799db59b tests/libcurses: remove wrong comments 2021-02-12 21:29:03 +00:00
rillig
ca234efa6a tests/libcurses: remove excess empty lines 2021-02-12 20:45:00 +00:00
rillig
450da2d661 tests/libcurses: query function arguments in consistent order 2021-02-12 20:41:37 +00:00
rillig
25ddeb49df tests/libcurses: don't access args directly
By providing declarative syntax for accessing the arguments, the
unnecessarily detailed boilerplate code is hidden.  This allows easy
inspection by tools and humans, to check for typos and other mistakes.
2021-02-12 18:20:05 +00:00
rillig
5326ff7afe tests/libcurses: replace ARG_CHTYPE_STRING with ARG_CHTYPE
All uses of the previous macro did not treat the argument as a string or
array of chtype, but as a single chtype.  It's strange that the previous
code arbitrarily split the access to the argument by first storing it as
a pointer and then dereferencing it.

No functional change.
2021-02-12 16:59:32 +00:00
rillig
a346ecb379 tests/libcurses: add shortcut macros for SCREEN and unsigned int 2021-02-12 16:49:18 +00:00
rillig
c7ac460c19 tests/libcurses: remove redundant comments
There is nothing surprising about call2, call3 or call4.
2021-02-12 14:05:57 +00:00
rillig
1fe7fa71d8 tests/libcurses: reduce boilerplate in function dispatcher
No functional change.  The generated code for GCC 9.3 on NetBSD 9.99.80
x86_64 is exactly the same as before.
2021-02-12 12:58:52 +00:00
rillig
b1b4392b00 tests/libcurses: reduce boilerplate in function dispatcher
This makes the code more declarative and easier to reason about.

The generated code stays exactly the same.
2021-02-12 08:55:32 +00:00
rillig
518cbcb21b tests/libcurses: add missing space after control flow keywords 2021-02-09 20:42:31 +00:00
rillig
6938509815 tests/libcurses: replace remaining strcasecmp with strcmp
There is no reason to write special functions in a different case than
the canonical one, just like for the regular curses functions.
2021-02-09 20:39:20 +00:00
rillig
e91849a6b1 tests/libcurses: fix spelling of the special call to DRAIN 2021-02-09 20:31:02 +00:00
rillig
82a08c1a4a tests/libcurses: compare function names case-sensitive
There is absolutely no reason to write function names in upper case or
mixed case.
2021-02-09 20:24:02 +00:00
rillig
74a9e3d2cc tests/libcurses: fix scanf parameter for unsigned int 2021-02-09 20:22:11 +00:00
rillig
03f821dbf2 tests/libcurses: fix off-by-one error in line numbers in diagnostics
I had broken this in testlang_parse.y 1.22 from 2021-02-07, when I
extracted the common 'eol' from the statements.  Extracting 'eol' had
the effect that the action for the statement was run before the line
number increased.

Now the line numbers in the diagnostics are the same again as before.

For lines that end with a backslash, the reported line number is the one
from the last of these lines, not the first one, also as before.  This
feature is not used by any of the current tests though.
2021-02-08 23:54:03 +00:00
joerg
cfe420e9b1 Don't define a label twice. 2021-02-08 23:50:25 +00:00
rillig
facc9c9e92 tests/libcurses: use consistent indentation for grammar rules 2021-02-08 20:55:42 +00:00
rillig
91cc09774d tests/libcurses: extract functions 'input' and 'noinput' from grammar 2021-02-08 20:39:33 +00:00
rillig
9e7915b0b6 tests/libcurses: indent grammar functions consistently 2021-02-08 20:26:46 +00:00
rillig
66374bbd09 tests/libcurses: declare %type in grammar
It looks as if the original author just didn't know how to declare the
type of non-terminals.  The explicit types in the '$' expressions were
all consistent.

No functional change.
2021-02-08 20:09:45 +00:00
rillig
9dc059c978 tests/libcurses: extract function 'delay_millis' from the grammar 2021-02-08 19:35:21 +00:00
rillig
b798190935 tests/libcurses: move function 'check' out of the grammar section
This removes the inconsistent indentation.
2021-02-08 19:28:08 +00:00
rillig
09f966d145 tests/libcurses: fix typo in license text 2021-02-08 19:15:20 +00:00
rillig
057f5777ce tests/libcurses: remove unused token DRAIN
There is a special function named 'DRAIN', but not a statement.  The
function name does not need its own token.
2021-02-08 19:09:59 +00:00
rillig
12fb37738f tests/libcurses: fix sentinel for execl
For systems where NULL is defined as a simple 0 or 0L.
2021-02-08 19:04:37 +00:00
rillig
dc127031c2 tests/libcurses: on errors, print nonprintable characters as well 2021-02-08 19:00:22 +00:00
rillig
7879077738 tests/libcurses: fix undefined behavior in test addch
The libcurses framework is not strictly typed and thus provides plenty
of ways to shoot yourself in the foot.  It's a waste of time debugging
things that a proper programming language can easily prevent.

The function addch expects an argument of type 'chtype'.  Passing a
"double-quoted" string does not match this, as 'chtype' is completely
different from a plain 'char'.  Instead, functions taking a 'chtype'
must be passed a `backtick-quoted` string.
2021-02-07 23:30:33 +00:00
rillig
1f48f93d43 tests/libcurses: use a single message style for diagnostics
Previously, there were several concurring styles:

	$msg in line %zu of file %s
	$msg line %zu of file %s
	%s, %zu: $msg

All these are now replaced with "%s:%zu: $msg".
2021-02-07 21:33:27 +00:00
rillig
9b3211a8fb tests/libcurses: make grammar for test cases conflict-free
No functional change.
2021-02-07 20:48:07 +00:00
rillig
9903d631af tests/libcurses: fix grammar for arrays
Previously, commas were completely ignored by the grammar.  Erroring out
on invalid characters made some of the tests fail since the comma was
not recognized anymore.  Add it back, but only for defining arrays.  It
would have been possible to leave out the commas or make them optional,
but since the current tests do not make use of that, keep the grammar as
strict as possible.

Fix an unclosed string literal in a test.  This had been wrongly
accepted before by the grammar.
2021-02-07 20:40:05 +00:00
rillig
925203b1c3 tests/libcurses: do not allow control characters in paths 2021-02-07 20:32:25 +00:00
rillig
c2ad8acebe tests/libcurses: error out on trying to parse /dev/zero
Be strict when parsing the tests.  Any unknown character is an error.
This avoids an endless loop when running "./director /dev/zero".  There
is no point in silently ignoring other invalid characters as well, as
this would only leave potential test writers in an unclear state,
without any benefit.
2021-02-07 20:27:40 +00:00
rillig
b30645eb36 tests/libcurses: fix documentation of call[234]
The function getyx is not a function but a macro.  It does not return
int, but void.  Since these changes destroy the simplicity of the
example, combining a regular return value and pass-by-reference return
values, I rewrote the whole section and added more examples.
2021-02-07 20:20:06 +00:00
rillig
ccd1df52a9 tests/libcurses: require keywords to be lowercase, except for OK and ERR
There is no need to write the keywords in upper case or mixed case.  The
only case where a keyword did not have the canonical form yet was a
single lowercase 'ok' in the test case 'innstr'.
2021-02-07 19:49:32 +00:00
rillig
183d5aec4d tests/libcurses: add missing semicolon in grammar 2021-02-07 19:44:34 +00:00
rillig
6989eb7749 tests/libcurses: fix typo in comment 2021-02-07 19:28:07 +00:00
rillig
1134970fd4 tests/libcurses: fix expected test output
The test framework doesn't check the files strictly, it only checks
whether the expected output is a prefix of the actual output, or vice
versa.  This allows several deviations to pass unnoticed, which is
wrong.
2021-02-07 18:56:37 +00:00
rillig
cfcf82e703 tests/libcurses: add const to some function parameters 2021-02-07 18:32:20 +00:00
rillig
58e6134faa tests/libcurses: simplify code for writing to the .exp file
If a write(2) returns less than 1, it must be an error.
2021-02-07 18:14:43 +00:00
rillig
bdb9e6b7f3 tests/libcurses: actually compare the stream to an absolute path
Up to now, the test command "compare /dev/null" was a no-op since the
command was only parsed but not run at all.  Now run it.

This makes the test mvwin fail.  That test will have to be fixed.

Comparing to /dev/null is certainly possible and may make sense,
comparing to /dev/zero is nonsense since the actual stream can never be
endless.  Some tests do that nevertheless, for whatever reason.

In order to have the expected test output closer to the curses commands
that cause it, it may be a good idea to add another command
'compare_str' that would work independently of an external file and at
the same time allow the expected output to be commented and explained.
This is not possible right now since the .chk files are read exactly
as-is.
2021-02-07 17:50:16 +00:00
rillig
1398f05953 tests/libcurses: use more common abbreviations for tokens 2021-02-07 17:32:55 +00:00
rillig
d3b5ee28db tests/libcurses: use standard indentation for grammar rule 'arg' 2021-02-07 17:26:15 +00:00
rillig
126b3d158a tests/libcurses: extract grammar rule 'arg' 2021-02-07 17:23:29 +00:00
rillig
aaac17ccef tests/libcurses: error out if called with too many arguments
This helps against users who try to add more options after the first
non-option argument and wonder why these options are silently ignored.
2021-02-07 13:56:23 +00:00
rillig
c1b0da3370 tests/libcurses: document another bug in the test director 2021-02-07 13:44:22 +00:00
rillig
fb153a60d3 tests/libcurses: fix usage of director 2021-02-07 13:22:23 +00:00
rillig
2eb448fe3b tests/libcurses: demonstrate more bugs in addch 2021-02-07 13:06:02 +00:00
rillig
4e30fe2ad3 tests/libcurses: fail on syntax errors in test files
Previously, a syntax error in a test file made the test pass, which was
outright dangerous.
2021-02-07 12:56:53 +00:00
rillig
d51c9371c9 tests/libcurses: use a single indentation style in the test grammar
The grammar rule 'args' has been left as-is since it needs to be split
into 'args' and 'arg' first, to avoid the redundancy.

The braces in "if (create_check_file)" were misleading.  It's strange that
GCC didn't reject this.
2021-02-07 12:48:34 +00:00
rillig
8de39c39e7 tests/libcurses: clean up test case grammar for statements
Previously, each statement ended with 'eol'.  This was unnecessarily
verbose since the 'eol' is not really part of the statement, it's part
of a line.

No functional change.
2021-02-07 12:24:18 +00:00
rillig
df2132f7f3 tests/libcurses: fix name of grammar rule
A list of assignments is not a statement, it's several statements.

No functional change.
2021-02-07 12:16:26 +00:00
rillig
a13a3f7e27 tests/libcurses: unary minus doesn't make sense on bool expressions
No functional change since -1 is as non-zero as 1.
2021-02-07 12:08:42 +00:00
rillig
4cf90fec0d tests/libcurses: allow end-of-line comments in data lines as well
This makes it possible to write small remarks directly in the affected
line, which not only makes for a clean visual appearance but also shows
up prominently in "cvs annotate" or "git blame", showing when such a
remark has been modified.
2021-02-07 12:05:36 +00:00
rillig
77df4d33b5 tests/libcurses: indent lexer code consistently
Several of the braces were misaligned.  For the simple keywords, there
is no need to write these braces at all, they only made the code look
more complicated than it really is.

I stumbled upon this because syntax errors in the test cases currently
let the test case succeed instead of fail, which is another ingredient
for unreliable tests, besides the loose output matching.
2021-02-07 11:52:43 +00:00
rillig
25d40489d1 libcurses: demonstrate bug in addch that doubles tab indentation
When adding "\t" via addch, win.curx advances by twice the spaces as
intended.  This bug was introduced somewhere between NetBSD 8.0 and 9.0.

Adding "\t" via addstr does not have this bug.

This bug causes the installation menu of sysinst to be have its menu
items indented by 16 characters instead of only 8.  This in turn
produces an ugly line break in the German translation.

The test framework for libcurses is not well integrated into ATF.
Whenever the expected output is longer than the actual output, or vice
versa, the test passes nevertheless.  This makes it necessary to
constantly look into atf-run.log to see whether the actual output is
indeed equal to the expected output, which is crucial, especially for
telling the difference between addstr and addnstr.

Reusing the .chk files for several tests is not a good idea either.  For
example, addstr and waddstr are supposed to produce the same result for
ASCII-only text, so it was tempting to use the same file.  But waddstr
seems to have a bug (maybe undefined behavior), at least waddstr returns
ERR in one case where it shouldn't.  This means that currently the
expected output (acknowledging the bug) must be different.

The "expected" test output in waddstr.chk looks completely broken, but
that's exactly what the test produces right now.
2021-02-07 01:53:54 +00:00
rillig
74e4499250 libcurses: fix typos in introduction to the curses test framework 2021-02-06 20:09:43 +00:00
martin
a9fe9302e9 Run all make tests as unprileged user - makes checking permission issues
a lot easier.
2021-02-06 19:00:25 +00:00
rillig
b9684d0f53 lint: update message text for 259 in test
That's the one place that is not checked for matching the actual message
by my usual pre-commit checks.
2021-02-04 07:39:39 +00:00
rillig
deb631d74d lint: add back "due to prototype" to message 259
That message is only supposed to warn about compatibility to traditional
C, in case the function should ever be compiled without its prototype
being in effect.  All other type checks are supposed to be in another
function, as documented, but that type check misses to report a few
error-prone type combinations (long to char, long to int).

30 years after the introduction of prototypes with C90, almost all
existing code uses prototypes.  The warning has thus lost most of its
usefulness and can rather be confusing since a conversion from 'char' to
'long' is not problematic with prototypes in action, and the probability
of the code being backported to a pre-C90 compiler is diminishingly
small.

The words "due to prototype" now serve as a hint again.  The proper fix
could be to suppress this warning in C99 mode since that's far enough
from traditional C.
2021-02-04 06:54:59 +00:00
rillig
1c1bd1bbee lint: document that message 108 doesn't abort anymore 2021-01-31 16:00:05 +00:00
rillig
70a1a91e7b lint: format tests in a common style
The lint tests do not focus on the whitespace since that is the most
boring part of code style.  Therefore, format the tests to be readable
by following share/misc/style as close as possible.
2021-01-31 14:57:28 +00:00
rillig
aadcb6a6f1 lint: add common header for all tests
For those tests that didn't use GCC-style line markers such as "# 2",
the line numbers of the diagnostics stay the same.  This is purely
conincidental.  Before, the 3 lines came from lint's built-in
definitions (see 'builtins' in main1.c), and line number counting
continued as if nothing had happened, making the first line of the
actual file line 4.  These 3 built-in lines are now replaced with 3
lines of file header.
2021-01-31 14:39:31 +00:00
rillig
9e66939b96 lint: reword message 259 about function argument conversion
The words "due to prototype" are an anachronism from the 1990s.
Nowadays every function is defined using a prototype, which makes these
words redundant.
2021-01-31 14:05:00 +00:00
rillig
43f40912b1 lint: make warning about function argument conversion more detailed
For every conversion it is useful to know both the source and the target
type since these are not always obvious from the code.

The only surprise is the warning in d_gcc_extension.  The conversion
there is from 'double' to 'long double', which is a lossless conversion.
This may be a bug in lint.
2021-01-31 13:56:14 +00:00
rillig
0b12920818 lint: demonstrate wrong and misleading warnings about reachability 2021-01-31 13:33:10 +00:00
rillig
eaade8c9b9 lint: add test for lossy assignments to bit-fields (164, 166) 2021-01-31 13:11:08 +00:00
rillig
2c260a3f3b lint: don't warn about constant condition in 'do { } while (0)' 2021-01-31 12:44:34 +00:00
rillig
7986832010 lint: add expectations to test for message 161 2021-01-31 12:30:53 +00:00
rillig
bed82d19b3 lint: add tests for 'constant in conditional context'
One of these tests explains why 'do { } while (0)' is so usual that
there is no reason to warn about it.  That warning will not survive for
long.
2021-01-31 12:29:16 +00:00
rillig
c4973480d0 lint: fix strange message about nested '==' operators
If one of the nested subexpressions is parenthesized, the author
probably knew how these expressions are evaluated.  Therefore don't warn
in such a situation.

Maybe the original author once made a typo and tried to initialize
variables but instead compared them, like this:

	int a, b, c;

	a == b == c;

This would explain the text of the message, which still sounds strange.
At least it doesn't show up as often anymore.
2021-01-31 12:20:00 +00:00
rillig
9ff24546ee lint: add more test cases for strange '==' warning 160 2021-01-31 11:59:56 +00:00
rillig
73fb62d3c1 lint: mention the operator in messages about bit shifts 2021-01-31 11:44:48 +00:00
rillig
6712cb633d lint: add quotes to messages 1 and 19 2021-01-31 11:23:01 +00:00
rillig
e9aa93027d lint: add expections to tests
msg_098: fix suffix for floating point constant
msg_127: remove prototype
msg_146: fix return type
2021-01-31 11:12:07 +00:00
rillig
d61a087385 lint: test messages 019 and 021 2021-01-31 09:48:47 +00:00
rillig
cfd7827cf3 lint: be more precise in message 003 "tag in argument list" 2021-01-31 09:26:27 +00:00
rillig
3cef4b4f94 lint: add a few more tests 2021-01-31 09:21:24 +00:00
rillig
c96543cdff lint: fix wrong 'expression has null effect' 2021-01-30 23:05:08 +00:00
rillig
d1d4e41c20 lint: add test for 129, possibly demonstrating a bug in lint 2021-01-30 22:38:54 +00:00
rillig
0872823424 lint: add test for message 259 about implicit conversions 2021-01-30 22:07:31 +00:00
rillig
4916b997a5 lint: remove message 189, add tests for a few other messages
Message 189 would have applied to traditional C and was supposed to
detect assignments between struct and union types.  The corresponding
check had never been implemented though.

Traditional C has been superseded for 30 years now, therefore there is no
point in adding this check retroactively.
2021-01-30 17:56:29 +00:00
rillig
3029566535 lint: add tests that trigger a few more messages 2021-01-30 17:02:58 +00:00
rillig
37de14639f lint: add test for message 325, undefined static function 2021-01-24 17:55:41 +00:00
rillig
e8cbbabf42 lint: add test for message 329, union cast with incompatible type 2021-01-24 17:44:37 +00:00
rillig
fe3677c509 lint: add tests for a few messages 2021-01-24 16:12:45 +00:00
rillig
1f640a49f4 lint: fix wrong warning about null pointer comparison 2021-01-24 11:21:58 +00:00
rillig
7b8d5df0f6 lint: demonstrate wrong 124 for flipped == as well
Since the fix in the next commit changes two places in the code, there
must be two wrong error messages that disappear then.
2021-01-24 11:17:44 +00:00
rillig
fc1964e307 lint: demonstrate wrong 124 due to bug in is_typeok_eq 2021-01-24 11:13:22 +00:00
rillig
adda8a3bab lint: document bug in typeok_eq
Since rt is an alias for rn->tn_type->t_tspec, it cannot be PTR and VOID
at the same time.  This makes the condition unsatisfiable.  Removing
that part of the code didn't show any change in behavior, as expected.

It may even be that fixing this obvious bug doesn't show any change in
behavior since that function is only used in a single place and
check_pointer_comparison performs its own checks before issuing any
warning.

At least the test cases added to msg_124.c all run as expected.
2021-01-24 10:50:42 +00:00
rillig
f2a08f3e9b lint: improve introduction of test d_c99_bool_strict_syshdr 2021-01-24 09:18:42 +00:00
rillig
378eb7af09 lint: explain why !finite(x) is not allowed in strict bool mode 2021-01-24 07:58:48 +00:00
rillig
4e7742bb74 lint: apply strict bool mode to lex.c
There are 2 remaining expressions:

In line 244, !(kw->kw_deco & deco) is a bitwise and.  This is already
allowed for enums, it needs to be allowed for arbitrary integer
expressions as well.  This covers the many places where plain integers
are used for bit fields, together with #define.  This pattern is not as
typesafe as using enums, still it is common practice.

In line 769, the expression !finite(f) is a legitimate use of a function
that has return type int for traditional reasons.  It's the same as for
ferror.

There are several other functions like unlink, open or strcmp that have
return type int as well, but with a different meaning.  It is not yet
clear what the best way is to handle these different meanings.  Having
to write finite(f) == 0 in strict bool mode doesn't look idiomatic, on
the other hand, !strcmp(s1, s2) is exactly the pattern that strict bool
mode wants to avoid.
2021-01-23 23:11:40 +00:00
rillig
9cd64a121c lint: fix error message for relaxed bool operations in system headers
In strict mode, allowing 1 as bool constant expression is probably not
needed in practice since most comparisons are != 0 instead of == 0.

Furthermore, in the expression (flags & 0x0002) == true, comparing with
true is misleading since the '==' operator can never evaluate to true in
this case.
2021-01-23 22:34:01 +00:00
rillig
4e2fcabaa8 lint: fix two wrong error messages in strict bool mode
The strict bool mode gets complicated because for system headers the
rules need to be relaxed since they cannot be changed easily, often not at all.

Still, if lint validates a program in strict bool mode, that program
must run with equal behavior regarding boolean expressions even on a
pre-C99 platform.
2021-01-23 22:20:17 +00:00
rillig
afdff4f65d lint: extend test for strict bool mode and system headers 2021-01-23 19:03:55 +00:00
chs
6ab81237dc for the busypage test, replace atf_tc_expect_fail() with atf_tc_skip()
because atf apparently has no way to expect a test program to crash.
fixes PR 55945.
2021-01-22 22:03:01 +00:00
simonb
14893fad26 Use .set noreorder and use reg names.
atf- lib/libc/sys/t_mprotect mprotect_mremap_exec is a bit happier now.
2021-01-21 00:56:41 +00:00
rillig
f7ed7c6314 lint: clean up code (mostly comments) 2021-01-18 20:02:34 +00:00
rillig
17f1c77b1c lint: fix assertion failure for restrict and _Thread_local 2021-01-18 17:43:43 +00:00
rillig
8981d6d027 lint: add more test cases for duplicate type qualifiers 2021-01-18 17:41:04 +00:00
simonb
b64a04d2b4 Check for MAP_FAILED instead of NULL when looking for an error from mmap(2). 2021-01-18 05:44:20 +00:00
rillig
8274970958 lint: allow system headers to use int as bool, even in strict bool mode 2021-01-17 23:04:09 +00:00
rillig
fb08819de8 lint: add more tests for system headers in strict bool mode 2021-01-17 23:00:41 +00:00
rillig
d5ff218b54 lint: add test for macro from system header in strict bool mode
Seen in usr.bin/make/meta.c:1670: FD_ZERO(&readfds).  These macros
cannot be fixed since system headers must not include <stdbool.h>.
Therefore INT constants should be accepted as controlling expressions as
well.
2021-01-17 21:19:06 +00:00
rillig
bf9c8d819d lint: add type information to message 126 2021-01-17 17:14:34 +00:00
rillig
8e597c87a3 lint: add test for incrementing const variable 2021-01-17 16:19:54 +00:00
rillig
2ba3ae8c78 lint: add test for rvalue ++ after cast 2021-01-17 16:16:09 +00:00
rillig
3bfc030e8c lint: add test for ordered comparison between incompatible types 2021-01-17 16:00:16 +00:00
rillig
129dd59395 lint: rename build_ampersand to build_address
At that stage of analysis, the ampersand is no longer ambiguous, it has
already been resolved as the address-of operator, instead of the
bitwise-and operator.
2021-01-17 14:45:21 +00:00
rillig
29d26eb8ed lint: in strict bool mode, don't treat bool as arithmetic type 2021-01-17 13:50:32 +00:00
rillig
4567bafeac lint: explain failing test case in strict bool mode 2021-01-17 13:15:03 +00:00
rillig
8974cec54a lint: demonstrate wrong error message in strict bool mode 2021-01-17 11:32:06 +00:00
rillig
8e0049026c lint: simplify typeok_strict_bool_compatible 2021-01-16 18:58:21 +00:00
rillig
bc43daba66 lint: add missing warning for bool() == int 2021-01-16 18:48:52 +00:00
rillig
68c2df6f3a lint: remove redundant calls to before_conversion 2021-01-16 17:54:22 +00:00
rillig
6caf229b90 lint: add test for missing check in strict bool mode 2021-01-16 16:58:39 +00:00
rillig
9f199e7ddf lint: in strict bool mode, integer constants do not have type bool
Previously, lint1 allowed integer constants such as 0 and 1 to be used
as bool constants.  This was only half-baked since after fixing all
error messages from that strict mode, there may still be integer
literals in the code that should be replaced with true or false.  This
would stop a migration from int to bool in the middle, leaving
inconsistent code around.

To find the remaining type inconsistencies, treat integers and bool as
completely incompatible, even for compile time constants.
2021-01-16 16:03:46 +00:00
rillig
2b74a6f1fa lint: prepare to make strict bool mode even stricter
Currently, strict bool mode still allows integer constant expressions to
be converted implicitly to bool.  This is something that other languages
such as Go, Java, C#, Pascal don't allow.

By providing a custom implementation of <stdbool.h> that defines false
and true to custom bool constant identifiers, lint will cover these
cases as well.

To prepare for this, reword the rules and restructure the tests in
d_c99_bool_strict.c.
2021-01-16 15:02:11 +00:00
rillig
a04184dc1f lint: normalize whitespace in tests 2021-01-16 12:57:37 +00:00
rillig
7425412f34 lint: add test for bool bit fields as operands of '|' 2021-01-15 23:15:28 +00:00
rillig
1ceef75ca4 lint: in strict bool mode, allow bool as operands of the comma operator 2021-01-15 22:07:54 +00:00
rillig
5160655d66 lint: demonstrate wrong message for comma operator 2021-01-15 22:04:27 +00:00
rillig
a738d648f3 lint: add tests for newly added messages for strict bool mode 2021-01-14 22:18:13 +00:00
rillig
4a20ca39ed lint: add type details to message for enum type mismatch
Before December 2020, it was cumbersome to add type information to a
message since the caller had to explicitly allocate buffers for the type
names.  That's probably the reason why this crucial detail had been left
out of the warning.
2021-01-14 07:42:31 +00:00
simonb
f5add44d28 Unmount and unconfigure in the reverse order that they were done. Fixes
problem with leaving a dangling snapshot configured.
2021-01-14 04:30:40 +00:00
skrll
95cbb4a14b skip sigbus_adraln on MIPS 2021-01-13 06:44:55 +00:00
rillig
58ad84b7ab lint: add new check for strict bool mode
In strict bool mode, bool is considered incompatible with all other
scalar types, just as in Java, C#, Pascal.

The controlling expressions in if statements, while loops, for loops and
the '?:' operator must be of type bool.  The logical operators work on
bool instead of int, the bitwise operators accept both integer and bool.
The arithmetic operators don't accept bool.

Since <stdbool.h> implements bool using C preprocessor macros instead of
predefining the identifiers "true" and "false", the integer constants 0
and 1 may be used in all contexts that require a bool expression.
Except from these, no implicit conversion between bool and scalar types
is allowed.

See usr.bin/tests/xlint/lint1/d_c99_bool_strict.c for more details.

The command line option -T has been chosen because all obvious choices
(-b or -B for bool, -s or -S for strict) are already in use.  The -T may
stand for "types are checked strictly".

The default behavior of lint doesn't change.  The strict bool check is
purely optional.

An example program for strict bool mode is usr.bin/make, which has been
using explicit comparisons such as p != NULL, ch != '\0' or n > 0 in
most places for a long time now, even before the refactoring in 2020.
2021-01-12 20:42:00 +00:00
christos
d25fab543f Only try to create up-to NAME_MAX filenames.
XXX: this should be moved to stdio/t_mktemp.c where the rest of the tests
are and the code lives.
2021-01-11 20:31:34 +00:00
skrll
6285957ff6 PR/55715: pmax testbed panics with "assertion "asid == curcpu()->ci_pmap_asid_cur" failed"
It's GXemul that has the bug! Unfortunately, there's no way (currently) to
detect if we're running under GXemul emulation, so disable for all mips
for now.  Hopefully, GXemul will get fixed soon.
2021-01-11 07:17:49 +00:00
rillig
bf28682f65 lint: extend test for strict _Bool handling
There is no danger in allowing (flags & FLAG) as a controlling
expression, provided that it is immediately compared to zero, such as in
an if statement or as the operand of a logical operator.
2021-01-11 00:28:28 +00:00
rillig
e9d1e169d3 lint: add enum flags to the test about strict boolean mode 2021-01-10 21:45:50 +00:00
rillig
465f117622 lint: allow custom flags to be specified in all unit tests
Previously, only the tests called msg_*.c could use this feature.  Since
it is useful for other tests as well, enable it everywhere.
2021-01-10 21:26:12 +00:00
skrll
8be367b3f6 PR/55715: pmax testbed panics with "assertion "asid == curcpu()->ci_pmap_asid_cur" failed"
disable the sigbus_adraln test on qemu for now
2021-01-10 20:46:14 +00:00
rillig
556f6964e2 lint: fix assertion failure for syntax error in enum declaration 2021-01-10 18:13:42 +00:00
rillig
0ec7a3ab6a lint: add test for triggering assertion failures in lint1 2021-01-10 18:06:38 +00:00
rillig
76d2ead3e0 lint: add test for treating _Bool as non-scalar type
This strict mode is not yet implemented.  The plan is to use it for
usr.bin/make, to get rid of the many possible variants of defining the
Boolean type in make.h.  These variants did find some bugs, but not
reliably so.  Using static analysis seems more promising for this.

In an early stage of developing this test, lint1 crashed in the enum
definition in line 213, where the node for the '?:' had been NULL.  This
can happen in other situations as well, such as with syntax errors, but
these should be rare, as lint is usually only run if the compiler has
accepted the source code.  Still, there should not be any assertion
failures while running lint1.
2021-01-10 17:43:46 +00:00
rillig
60d8513049 lint: use message 232 for unused label in function
This message had been defined but not used before.
2021-01-10 13:54:13 +00:00
rillig
c7eced1ab4 lint: explain missing error for _Bool constant expressions 2021-01-10 13:17:24 +00:00
rillig
a90a871c79 lint: fix conversion of non-constant scalar to _Bool 2021-01-10 12:46:38 +00:00
rillig
f8cc76a76d lint: fix conversion of constant expressions to _Bool 2021-01-10 12:34:56 +00:00
rillig
9d90fb23fe lint: add test for converting non-constant expressions to _Bool 2021-01-10 12:29:46 +00:00
rillig
e107438c00 lint: demonstrate wrong handling of conversion to _Bool 2021-01-10 11:24:42 +00:00
rillig
6bb8504ff5 lint: add test for 116 "illegal pointer subtraction" 2021-01-09 22:55:36 +00:00
rillig
1043e742ed lint: fix crash for error 108 (invalid type of unary operator) 2021-01-09 17:21:33 +00:00
rillig
fe02f4b2ac lint: add test for message 108, which currently crashes 2021-01-09 17:02:19 +00:00
rillig
232122fb53 lint: add test for message 160 2021-01-09 15:32:06 +00:00
rillig
e3ae774eba lint: add tests for messages 117, 120, 125, 127 2021-01-09 14:37:16 +00:00
rillig
6b6b847fc8 lint: allow tests to specify additional flags
Several of the tests only need to add the -p flag.  Mentioning the
(current) default flags in each of these tests is redundant.  Therefore,
allow them to specify "lint1-extra-flags: -p" instead of the current
"lint1-flags: -g -S -w -p".
2021-01-09 14:33:53 +00:00
rillig
af03d2a051 lint: add tests for several messages 2021-01-08 21:25:03 +00:00
rillig
dbe5d068b4 lint: fix function as controlling expression (since 2020-12-31)
It's perfectly valid to directly use a function name as the controlling
expression of an if statement.  That function name is converted
implicitly to a pointer to that function, and that is a scalar value
then.

Spotted by christos in lib/libpthread/pthread.c:634.
2021-01-08 02:11:45 +00:00
rillig
91017b3441 lint: demonstrate wrong message 204 (since 2020-12-31)
In func.c 1.39 from 2020-12-31 18:51:28, the check that controlling
expressions are indeed scalar was extended from while and for loops to
if statements as well.  It just seemed to have been an oversight.

This revealed a bug in lint, which didn't accept the following valid
code snippet from lib/libpthread/pthread.c:634:

	void _malloc_thread_cleanup(void) __weak;
	...
	if (_malloc_thread_cleanup)
		_malloc_thread_cleanup();

Testing a function (instead of a function pointer) for truthiness is
probably rare since most functions are defined unconditionally.  For
weak functions it comes in handy though.

Clang-Tidy suggests to prefix the function with '&' to silence its
warning.  Doing that revealed a non-obvious behavior in build_ampersand,
which does not add the AMPER node to the expression even though it is
clearly mentioned in the code.  That is left for further research.

Once the original bug is fixed, it probably doesn't matter whether the
AMPER is discarded or retained since check_controlling_expression would
add it back.  There's probably a reason though to sometimes discard the
AMPER and sometimes retain it.
2021-01-08 01:40:03 +00:00
rillig
09a916ab1d lint: revert test for message 11
That test only produced other messages, but not message 11.
2021-01-07 19:11:58 +00:00
rillig
d8ecd506c6 lint: add tests for some messages 2021-01-07 18:37:41 +00:00
joerg
7c219dd6db Optimize nbperf
- add fudge mode which gives a slightly slower hash function, but works
  almost always in the first iteration by avoiding degenerate edges
- avoid keeping incidence lists around reducing the memory foot print by
  30%
- split edge processing from hashing as in the non-fudge case it is a
  reasonable costly part that often gets thrown away
- merge graph2 and graph3 routines now that they are mostly the same
2021-01-07 16:03:08 +00:00
rillig
7d8d33cba8 lint: add tests for messages 93, 94, 95, 96, 97, 98, 99 2021-01-07 00:38:46 +00:00
rillig
1aa2d3570d lint: fix test for message 324 on i386
i386 is an ILP32 platform (arch/i386/targparam.h).  On these platforms,
int and long have the same size, and even with the -p option for
portability checks, INT_RSIZE in inittyp.c is defined to 4, not 3.

Because of this, in check_integer_conversion, psize(nt) was not greater
than psize(ot), and the warning was not issued.

To make the test behave the same on all platforms, changed the long
variables to long long, since long long is 64-bit on all platforms, and
int is 32-bit.
2021-01-06 09:23:04 +00:00
rillig
15275571de lint: remove redundant symbolic operator names
These symbolic names for INCBEF, INCAFT, DECBEF and DECAFT were
non-standard and thus confusing.  All other operators were as expected.
Now that the operator names from ops.def are very similar, there is no
need to keep to almost identical lists around.

No change to the user-visible messages since the only place where these
operator names were used was in 324, and that message was restricted to
PLUS, MINUS, MULT and SHL.
2021-01-05 23:20:53 +00:00
rillig
b8104292aa lint: clean up symbolic operator names that are used in the messages
Including the "p" in the symbolic operator names was questionable, for
several reasons:

1.  The "p" could be taken to mean an actual variable name, which is
    confusing if the function doesn't have such a variable, or even more
    so if the line contains an unrelated variable called "p".

2.  For the binary operators, having the "p" mentioned on both sides of
    the operator (such as in "p + p") wrongly suggested that both
    operands of the expression were the same.

3.  The name "p" often stands for a pointer.  Most of the operators
    don't accept pointers, therefore the name was misleading.

For these reasons, the "p" was removed from the symbolic name of all
operators.  This makes several pairs of operators indistinguishable:

    INCBEF == INCAFT
    DECBEF == DECAFT
    UPLUS == PLUS
    UMINUS == MINUS
    STAR == MULT
    AMPER == AND

This is not expected to create any confusion since C programmers are
expected to know these double meanings.

The symbolic names for SHLASS and SHRASS were missing the '=' before.
This was added since omitting it was probably an oversight.
2021-01-05 23:07:49 +00:00
rillig
3796e6d449 lint: add test for "suggest cast" [324]
This warning is the only one that calls print_tnode, which in turn uses
the redundant operator names in str_op_t.

There is another list of operator names in ops.c, but those names
include more clutter, for example "p + p" instead of a simple "+".
Using those operator names would therefore rather be confusing. These
two lists should be merged, to remove unnecessary redundancy.
2021-01-05 22:38:51 +00:00
rillig
9a3fecd259 lint: fix bug in "precedence confusion possible [169]" 2021-01-04 23:50:46 +00:00
rillig
6c2a2c1402 lint: document and demonstrate the bug in check_precedence_confusion
It took quite a while to get to the correct interpretation of this small
piece of code and to draw the right conclusions from it.  Now the bug is
finally ready to be fixed, as already announced in the test.
2021-01-04 23:47:26 +00:00
rillig
8f3340157a lint: finish the comments in check_precedence_confusion 2021-01-04 22:41:56 +00:00
rillig
d2a5bcaf42 lint: add test for "precedence confusion possible [169]" 2021-01-04 15:52:51 +00:00
rillig
84a4b4d862 lint: add test for 265 "c89 C does not support 'long long'" 2021-01-03 20:20:01 +00:00
rillig
bd792b2822 lint: fix spelling of message 308
All other messages are lowercase as well.
2021-01-03 16:59:59 +00:00
rillig
87ac1cfc83 lint: add detailed type information for functions 2021-01-03 15:55:18 +00:00
rillig
6add3c2232 lint: add type information to message 124 "illegal pointer combination" 2021-01-03 15:51:16 +00:00
rillig
5ba1c48094 lint: add test for message 124 "illegal pointer combination"
The message may be correct, but it is not helpful in any way.  There are
just too many function pointers that may differ in a very small detail.

Before tyname.c 1.20 from 2021-01-02, the string representation of type
names was often limited to only 63 characters.  Because of this, it made
sense to omit any detail that could need more space than this.  Now that
this limitation is gone, it's reasonable to add more detail to the type
information, especially since that information is readily available.
2021-01-03 15:44:35 +00:00
rillig
8a6c8bc42b lint: add tests for some of the messages 2021-01-03 15:35:00 +00:00
rillig
e201064a7a lint: fix integration test
The body of an ATF test must never return 1 but instead report failure
via atf_fail.  Otherwise the following error message appears:

    Failed: Test case body returned a non-ok exit code, but this is
    not allowed

The test program t_integration intentionally bypasses the official ATF
API for performance reasons.  But even then, it should stick to the API
as close as possible.
2021-01-02 19:22:42 +00:00
rillig
ad4fbc2570 lint: add a few more tests
No serious bugs found this time.
2021-01-02 18:06:01 +00:00
rillig
5827a84bf2 lint: fix message 308 "Invalid type for _Complex"
Previously, lint aborted since it didn't expect tspec_name to be called
with NOTSPEC, which at that point was the only possible value of
dcs->d_cmod.
2021-01-02 17:17:00 +00:00
rillig
4b1f579b14 lint: add test for message 308 "Invalid type %s for _Complex" 2021-01-02 16:55:45 +00:00
rillig
a52e33d19b lint: allow _Bool for bit-fields 2021-01-02 16:33:39 +00:00
rillig
0eb1390092 lint: fix and document test for illegal bit-fields
The _Complex bit-field should have been commented out.
2021-01-02 16:12:39 +00:00
rillig
9a83ddef77 lint: add test for message 35: illegal bit-field type
Bug: _Bool is not accepted as a bit-field, but it should be.

Bug: lint aborts in a controlled manner with message "common/tyname.c,
190: tspec_name(0)" when it sees a declaration of a _Complex bit-field.
(Not that a _Complex bit-field would make any sense.)
2021-01-02 15:55:54 +00:00
rillig
5281bfe656 lint: demonstrate that -t mode is practically unusable
Since main1.c from 2014-04-18, running lint in -t mode produces strange
warnings in lines 1 to 3 of no file at all.

This is caused by the builtins that are parsed in main().  These
builtins are incompatible with traditional mode because they use long
double, which had not been known at that time.
2021-01-02 11:12:34 +00:00
rillig
a0a15c1464 lint: add a test for each message produced by lint1
Having a test for each message ensures that upcoming refactorings don't
break the basic functionality.  Adding the tests will also discover
previously unknown bugs in lint.

The tests ensure that every lint message can actually be triggered, and
they demonstrate how to do so.  Having a separate file for each test
leaves enough space for documenting historical anecdotes, rationale or
edge cases, keeping them away from the source code.

The interesting details of this commit are in Makefile and
t_integration.sh.  All other files are just auto-generated.

When running the tests as part of ATF, they are packed together as a
single test case.  Conceptually, it would have been better to have each
test as a separate test case, but ATF quickly becomes very slow as soon
as a test program defines too many test cases, and 50 is already too
many.  The time complexity is O(n^2), not O(n) as one would expect.
It's the same problem as in tests/usr.bin/make, which has over 300 test
cases as well.
2021-01-02 10:22:42 +00:00
rillig
c1c5b23632 lint: fix wrong warning about bitfield in C99 structure initialization
The variable namemem is supposed to be a circular list, which is
"documented" implicitly in push_member.

The implementation was buggy though.  In pop_member, the circular list
was destroyed though.  Given the list (capital, major, favorite_color,
green), removing capital made major point to itself in the forward
direction, even though it should not have been modified at all.

In the test, I had been too optimistic to quickly understand the code
around variable initialization.  I was wrong though, so I had to adjust
the comments there to reality.
2021-01-01 19:11:19 +00:00
rillig
59e2f0df9e lint: demonstrate bug in handling of nested C9X struct initializers 2021-01-01 16:50:47 +00:00