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

Buildbot grammar #37825

Closed
wants to merge 8 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ matrix:
- env: IMAGE=x86_64-gnu-debug
- env: IMAGE=x86_64-gnu-nopt
- env: IMAGE=x86_64-gnu-make
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1
- env: IMAGE=x86_64-gnu-llvm-3.7 RUST_BACKTRACE=1
- env: IMAGE=x86_64-gnu-grammartest ALLOW_PR=1
- env: IMAGE=x86_64-musl

# OSX builders
Expand Down
15 changes: 15 additions & 0 deletions src/ci/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Testing containers locally

Make sure, you have all required modules unpacked:
```
git submodule update --init
```

Use the `run.sh` from `src/ci/docker`.
The `src/ci/run.sh` is used inside the container.

```
src/ci/docker/run.sh x86_64-gnu-grammartest
```

You can choose one of the targes from `src/ci/docker`.
30 changes: 30 additions & 0 deletions src/ci/docker/x86_64-gnu-grammartest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ubuntu:16.10

RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
make \
file \
curl \
ca-certificates \
python \
git \
cmake \
ccache \
sudo \
gdb \
llvm-3.9-tools \
libedit-dev \
zlib1g-dev \
antlr4 \
bison \
flex \
openjdk-8-jdk-headless

RUN cd /usr/local/lib && curl http://www.antlr.org/download/antlr-4.5.3-complete.jar -o antlr-complete.jar

ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \
--llvm-root=/usr/lib/llvm-3.9
ENV RUST_CHECK_TARGET check-grammar
RUN mkdir /tmp/obj
RUN chmod 777 /tmp/obj
15 changes: 14 additions & 1 deletion src/grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

Uses [antlr4](http://www.antlr.org/) and a custom Rust tool to compare
ASTs/token streams generated. You can use the `make check-lexer` target to
run all of the available tests.
run all of the available tests or `make check-grammar` and focus on the grammar checks.

The build of the rust part is included with `make tidy` and can be run with `make check-build-lexer-verifier`.

## Running one grammar test

First you need to setup your environment:
```
./configure
make check-grammar
```

Then run the check you would like:
```
grammar/parser-lalr < src/test/compile-fail/E0063.rs
```

# Manual build

To use manually, assuming antlr4 ist installed at `/usr/share/java/antlr-complete.jar`:
Expand Down
7 changes: 5 additions & 2 deletions src/grammar/parser-lalr-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
// Forward declare strdup from <string.h> to avoid warning during compilation
char *strdup(const char *s);

extern int yylex();
extern int rsparse();


#define PUSHBACK_LEN 4

static char pushback[PUSHBACK_LEN];
Expand Down Expand Up @@ -73,7 +76,7 @@ int n_nodes;
struct node *mk_node(char const *name, int n, ...) {
va_list ap;
int i = 0;
unsigned sz = sizeof(struct node) + (n * sizeof(struct node *));
unsigned int sz = sizeof(struct node) + (n * sizeof(struct node *));
struct node *nn, *nd = (struct node *)malloc(sz);

print("# New %d-ary node: %s = %p\n", n, name, nd);
Expand Down Expand Up @@ -114,7 +117,7 @@ struct node *mk_none() {
struct node *ext_node(struct node *nd, int n, ...) {
va_list ap;
int i = 0, c = nd->n_elems + n;
unsigned sz = sizeof(struct node) + (c * sizeof(struct node *));
unsigned int sz = sizeof(struct node) + (c * sizeof(struct node *));
struct node *nn;

print("# Extending %d-ary node by %d nodes: %s = %p",
Expand Down
6 changes: 5 additions & 1 deletion src/grammar/testparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@

for parser in args.parser:
filename = os.path.basename(parser) + '.bad'
print("writing {} files that did not yield the correct result with {} to {}".format(len(bad[parser]), parser, filename))
bad_tests = len(bad[parser])
print("writing {} files that did not yield the correct result with {} to {}\n".format(bad_tests, parser, filename))
with open(filename, "w") as f:
for p in bad[parser]:
print("bad test: {}".format(p))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this output because the output file will be lost with the container.

f.write(p)
f.write("\n")
if bad_tests > 0:
exit(1)
14 changes: 7 additions & 7 deletions src/test/compile-fail/E0063.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ struct TruncatedPluralFoo {

fn main() {
let w = SingleFoo { };
//~^ ERROR missing field `x` in initializer of `SingleFoo`
//~| NOTE missing `x`
//~error[E0063]: missing field `x` in initializer of `SingleFoo`
//~^^^ missing `x`
let x = PluralFoo {x: 1};
//~^ ERROR missing fields `y`, `z` in initializer of `PluralFoo`
//~| NOTE missing `y`, `z`
//~error[E0063]: missing fields `y`, `z` in initializer of `PluralFoo`
//~^^^ missing `y`, `z`
let y = TruncatedFoo{x:1};
//~^ missing fields `a`, `b`, `y` and 1 other field in initializer of `TruncatedFoo`
//~| NOTE `a`, `b`, `y` and 1 other field
//~^^^ `a`, `b`, `y` and 1 other field
let z = TruncatedPluralFoo{x:1};
//~^ ERROR missing fields `a`, `b`, `c` and 2 other fields in initializer of `TruncatedPluralFoo`
//~| NOTE missing `a`, `b`, `c` and 2 other fields
//~error[E0063]: missing fields `a`, `b`, `c` and 2 other fields in initializer of `TruncatedPluralFoo`
//~^^^ missing `a`, `b`, `c` and 2 other fields
}