aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/compiler_test.go
Commit message (Collapse)AuthorAgeFilesLines
* all: remove loop variables scopingTaras Madan2025-02-171-3/+0
|
* pkg/compiler: allow manual consts to override auto-extracted constsDmitry Vyukov2024-11-261-0/+21
| | | | | | | | | | | | | | | | | | | | Currently if const values in 2 .const files have different value, the compiler produces an error. This is problematic for auto-extacted consts since we extract them for only 1 arch now. So if a const has different values for different arches, auto-extacted consts may not reflect that, and we can get a mismatch with manual descriptions that has correct values for all arches. So if both manual and auto-extacted consts have different values, silently prefer the manual ones. I've tried to do some whitelisting of consts during auto-extaction, but the list is large and changing over time. This solution is not perfect since the manual descriptions may have a bug, and the mismatch is actually pointing to that bug. Maybe in future we could extract for all arches separately, or do something else. But let's do this for now.
* executor: remove noshmem modeDmitry Vyukov2024-06-041-1/+1
| | | | | | | | | All OSes we have now support shmem. Support for Fuchia/Starnix/Windows wasn't implemented, but generally they support shared memory. Remove all of the complexity and code associated with noshmem mode. If/when we revive these OSes, it's easier to properly implement shmem mode for them.
* prog: fix panic during squashingDmitry Vyukov2024-05-031-0/+30
| | | | | | | | | Netbsd syzbot instance crashes trying to squash a pointer. Pointers must not be squashed. This happens because of recursive ucontext_t type that contains a pointer to itself. When we assign SquashableElem recursive struct types may not be fully generated yet, and ForeachArgType won't observe all types. Assign SquashableElem after all types are fully generated.
* tools/syz-linter: check t.Logf/Errorf/Fatalf messagesDmitry Vyukov2024-04-171-4/+4
| | | | | Fix checking of Logf, it has string in 0-th arg. Add checking of t.Errorf/Fatalf.
* compiler: correctness test for flags flatteningPaul Chaignon2023-12-051-0/+50
| | | | | | | | | | | | This commit adds a new compiler test to check that the int and string flags are correctly flattened. That is, they contain the expected values after flattening. Note that for string flags, the compiler adds null bytes at the end of all strings it processes. We must therefore add the same to the expected output string flags. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
* sys: refactor const extractionAleksandr Nogikh2023-10-041-2/+6
| | | | | 1) Make FabricateSyscallConsts() operate on ConstFile. 2) Expose Pos inside ConstInfo.
* all: ioutil is deprecated in go1.19 (#3718)Taras Madan2023-02-231-2/+2
|
* pkg/compiler: fix almost infinite recursion in template instantiationDmitry Vyukov2021-10-051-0/+10
| | | | | Fix another cases where recurion is finite but fan out factor is large, so our recursion check would take 5^10 iterations to handle this.
* pkg/compiler: fix infinite recursion in template instantiationDmitry Vyukov2021-10-051-0/+9
| | | | | | | | | | | | | Fix a bug found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17240 We handled the case of infinite recursion in templates but only if the full type name matches precisely (A -> B -> A). In this case the name constantly changes due to different template arguments. Per se this is a not an error (and we have real cases that use this, e.g. when an nlattr_t contains nested nlattr_t's), but it's an error if it recurses infinitely. Restrict recursion on the same template to 10 levels.
* pkg/compiler: fix crash on invalid templatesDmitry Vyukov2020-11-181-0/+8
| | | | | Discovered by go-fuzz/OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27599
* sys/targets: add OS/Arch name constsDmitry Vyukov2020-10-261-5/+5
| | | | | | | | | | | | We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere.
* pkg/compiler: merge const files into a single fileDmitry Vyukov2020-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | We now have 8 arches for Linux and .const files produce lots of noise in PRs and lots of diffs. If 3 .txt files are touched, the PR will have 24 .const files, which will be intermixed with .txt files. Frequently const values are equal across arches, and even if they don't spreading a single value across 8 files is inconvinient. Merge all 8 *_arch.const files into a single .const file. See the test for details of the new format. The old format is still parsed for now, we can't update all OSes at once. For Linux this reduces number of const files/lines from 1288/96599 to 158/11603. Fixes #1983
* prog: remove StructDescDmitry Vyukov2020-05-031-4/+0
| | | | | | | | | | | | Remove StructDesc, KeyedStruct, StructKey and all associated logic/complexity in prog and pkg/compiler. We can now handle recursion more generically with the Ref type, and Dir/FieldName are not a part of the type anymore. This makes StructType/UnionType simpler and more natural. Reduces size of sys/linux/gen/amd64.go from 5201321 to 4180861 (-20%). Update #1580
* pkg/compiler: check that flags values fit into base typeDmitry Vyukov2020-03-171-0/+2
| | | | | | | | flags[foo, int8] foo = 0x12345678 is always an error, detect these cases. Found some bugs in mptcp, packet sockets, kvm.
* pkg/compiler: reduce clutter in test outputDmitry Vyukov2020-03-171-1/+5
| | | | Don't prefix each error with test file:line (which is pointless in this case).
* pkg/compiler: unshare error handlerDmitry Vyukov2020-03-171-0/+3
| | | | | eh is shared across several tests and uses wrong t. Unshare it.
* pkg/compiler: add tests for generation phaseDmitry Vyukov2020-03-171-98/+36
| | | | | | Add errors3.txt with tests for errors that are produced during generation phase. Refactor tests to reduce duplication. Tidy struct/union size errors: better locations and make testable.
* pkg/compiler: don't specify syscall consts for test OSDmitry Vyukov2020-03-171-6/+6
| | | | This is just tedious. Fabricate them on the fly.
* pkg/compiler: handle errors in testDmitry Vyukov2020-03-171-2/+5
| | | | | Currnetly we don't have any errors in this test, but if we get some, it crashes with nil deref.
* pkg/compiler: fix infinite recursion in template instantiationDmitry Vyukov2019-10-101-0/+5
| | | | | | | | | Currently we replace a template argument and then recurse into the new type AST to see if there is more to replace. If the description is buggy and the template argument contains itself, then we will recurse infintiely trying to replace it more and more. Use post-order traversal when replacing template argument to fix this.
* pkg/ast: fix out-of-bounds accessDmitry Vyukov2019-07-301-1/+1
| | | | | Scanner can access data out of bounds on bad input. Also fix regression fuzz test to be able to detect the bug.
* pkg/compiler: refactor regression fuzz testDmitry Vyukov2019-07-301-11/+5
| | | | | Reuse most of the existing Fuzz function rather than duplicate the logic.
* pkg/compiler: fix potential nil derefDmitry Vyukov2019-03-061-0/+2
| | | | One one found on fuzzbuzz.io.
* pkg/compiler: fix infinite recursion on unionsDmitry Vyukov2019-03-051-1/+4
| | | | Found by go-fuzz on fuzzbuzz.
* pkg/compiler: don't warn about the same len twiceDmitry Vyukov2019-01-311-0/+30
| | | | Also add tests for warnings while we are here.
* pkg/compiler: add error handler in CollectUnusedMarco Vanotti2018-11-211-0/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * pkg/compiler: Add error handler in `CollectUnused`. This commit adds an error handler for the `CollectUnused` function. The error handler just panics on any error, but is useful for debugging. The error handler is used any time `comp` finds an error, and if it's missing, it will panic due to a `nil` pointer dereference. At least now we get a better understanding of the errors. The only user of `CollectUnused` is `sys/fuchsia/fidlgen`, which is failing now and will be fixed in a future commit. The output message looks like this: ``` panic: could not collect unused nodes. fidl_net-stack.txt:110:15: unknown type zx_chan_zircon_ethernet_Device_client ``` * pkg/compiler Better error handling in CollectUnused This commit changes the default error handler for compiler to `ast.LoggingHandler`, meaning that if `nil` is passed as an error handler, `LoggingHandler` will be used instead. `CollectUnused` now returns an error if any of the subfunctions produce errors. `fidlgen` is the only caller of `CollectUnused`, and now checks for errors as well. * pkg/compiler Add tests for CollectUnused This commit adds basic tests for the CollectUnused function. There's one test that checks that it returns the right nodes, and another one that makes sure that it returns errors when needed. To make the test clearer, I had to add the error handler as an explicit parameter in `CollectUnunsed`, instead of using the default one. This avoid printing garbage in the logs. The `TestCollectUnusedError` function uses a nopErrorHandler to avoid printing anything. * pkg/compiler fix presubmit warnings
* executor: overhaulDmitry Vyukov2018-07-241-13/+13
| | | | | | | | | | | | | | | | | Make as much code as possible shared between all OSes. In particular main is now common across all OSes. Make more code shared between executor and csource (in particular, loop function and threaded execution logic). Also make loop and threaded logic shared across all OSes. Make more posix/unix code shared across OSes (e.g. signal handling, pthread creation, etc). Plus other changes along similar lines. Also support test OS in executor (based on portable posix) and add 4 arches that cover all execution modes (fork server/no fork server, shmem/no shmem). This change paves way for testing of executor code and allows to preserve consistency across OSes and executor/csource.
* pkg/ast: support char constantsDmitry Vyukov2018-04-291-1/+12
| | | | | | | Frequently it's useful to do something like: int8['a':'z'] punctuation = ',', '-', ':'
* pkg/compiler: support type templatesDmitry Vyukov2018-01-131-7/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Netlink descriptions contain tons of code duplication, and need much more for proper descriptions. Introduce type templates to simplify writing such descriptions and remove code duplication. Note: type templates are experimental, have poor error handling and are subject to change. Type templates can be declared as follows: ``` type buffer[DIR] ptr[DIR, array[int8]] type fileoff[BASE] BASE type nlattr[TYPE, PAYLOAD] { nla_len len[parent, int16] nla_type const[TYPE, int16] payload PAYLOAD } [align_4] ``` and later used as follows: ``` syscall(a buffer[in], b fileoff[int64], c ptr[in, nlattr[FOO, int32]]) ```
* sys: support type aliases (aka typedefs)Dmitry Vyukov2018-01-081-19/+30
| | | | | | | | | | | | | | | | | | | | | | Complex types that are often repeated can be given short type aliases using the following syntax: ``` type identifier underlying_type ``` For example: ``` type signalno int32[0:65] type net_port proc[20000, 4, int16be] ``` Then, type alias can be used instead of the underlying type in any contexts. Underlying type needs to be described as if it's a struct field, that is, with the base type if it's required. However, type alias can be used as syscall arguments as well. Underlying types are currently restricted to integer types, `ptr`, `ptr64`, `const`, `flags` and `proc` types.
* sys/syz-extract: support fuchsiaDmitry Vyukov2017-09-251-2/+3
|
* all: more assorted fuchsia supportDmitry Vyukov2017-09-221-4/+5
|
* sys: move linux descriptions to sys/linuxDmitry Vyukov2017-09-151-2/+2
|
* sys, pkg/compiler: move padding computation to compilerDmitry Vyukov2017-09-041-0/+30
| | | | This makes types constant during execution, everything is precomputed.
* pkg/compiler: use correct arch ptr sizeDmitry Vyukov2017-09-041-3/+3
|
* pkg/compiler: detect resources without ctorsDmitry Vyukov2017-09-041-1/+1
| | | | Fixes #217
* pkg/compiler: verify validity of len targetsDmitry Vyukov2017-09-041-9/+13
| | | | Update #217
* pkg/compiler: check and generate typesDmitry Vyukov2017-09-021-5/+23
| | | | | | Move most of the logic from sysgen to pkg/compiler. Update #217
* pkg/compiler: more static error checkingDmitry Vyukov2017-08-271-52/+17
| | | | Update #217
* pkg/compiler: move more const-processing code to compilerDmitry Vyukov2017-08-271-0/+21
|
* pkg/compiler, sys/syz-sysgen: move const handling to pkg/compilerDmitry Vyukov2017-08-271-5/+11
| | | | Now pkg/compiler deals with consts.
* sys/syz-extract: switch to the new parserDmitry Vyukov2017-08-181-0/+59