mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #3356 from amscanne:generics_tests
PiperOrigin-RevId: 323066414
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
FROM fedora:31
|
||||
# Install bazel.
|
||||
RUN dnf install -y dnf-plugins-core && dnf copr enable -y vbatts/bazel
|
||||
RUN dnf install -y git gcc make golang gcc-c++ glibc-devel python3 which python3-pip python3-devel libffi-devel openssl-devel pkg-config glibc-static libstdc++-static patch
|
||||
RUN dnf install -y git gcc make golang gcc-c++ glibc-devel python3 which python3-pip python3-devel libffi-devel openssl-devel pkg-config glibc-static libstdc++-static patch diffutils
|
||||
RUN pip install pycparser
|
||||
RUN dnf install -y bazel3
|
||||
# Install gcloud.
|
||||
|
||||
@@ -12,27 +12,3 @@ go_binary(
|
||||
visibility = ["//:sandbox"],
|
||||
deps = ["//tools/go_generics/globals"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "go_generics_tests",
|
||||
srcs = glob(["generics_tests/**"]) + [":go_generics"],
|
||||
outs = ["go_generics_tests.tgz"],
|
||||
cmd = "tar -czvhf $@ $(SRCS)",
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "go_generics_test_bundle",
|
||||
srcs = [
|
||||
":go_generics_tests.tgz",
|
||||
":go_generics_unittest.sh",
|
||||
],
|
||||
outs = ["go_generics_test.sh"],
|
||||
cmd = "cat $(location :go_generics_unittest.sh) $(location :go_generics_tests.tgz) > $@",
|
||||
executable = True,
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "go_generics_test",
|
||||
size = "small",
|
||||
srcs = ["go_generics_test.sh"],
|
||||
)
|
||||
|
||||
@@ -100,20 +100,21 @@ def _go_template_instance_impl(ctx):
|
||||
|
||||
# Build the argument list.
|
||||
args = ["-i=%s" % template.file.path, "-o=%s" % output.path]
|
||||
args += ["-p=%s" % ctx.attr.package]
|
||||
if ctx.attr.package:
|
||||
args.append("-p=%s" % ctx.attr.package)
|
||||
|
||||
if len(ctx.attr.prefix) > 0:
|
||||
args += ["-prefix=%s" % ctx.attr.prefix]
|
||||
args.append("-prefix=%s" % ctx.attr.prefix)
|
||||
|
||||
if len(ctx.attr.suffix) > 0:
|
||||
args += ["-suffix=%s" % ctx.attr.suffix]
|
||||
args.append("-suffix=%s" % ctx.attr.suffix)
|
||||
|
||||
args += [("-t=%s=%s" % (p[0], p[1])) for p in ctx.attr.types.items()]
|
||||
args += [("-c=%s=%s" % (p[0], p[1])) for p in ctx.attr.consts.items()]
|
||||
args += [("-import=%s=%s" % (p[0], p[1])) for p in ctx.attr.imports.items()]
|
||||
|
||||
if ctx.attr.anon:
|
||||
args += ["-anon"]
|
||||
args.append("-anon")
|
||||
|
||||
ctx.actions.run(
|
||||
inputs = [template.file],
|
||||
@@ -151,7 +152,7 @@ go_template_instance = rule(
|
||||
"consts": attr.string_dict(),
|
||||
"imports": attr.string_dict(),
|
||||
"anon": attr.bool(mandatory = False, default = False),
|
||||
"package": attr.string(mandatory = True),
|
||||
"package": attr.string(mandatory = False),
|
||||
"out": attr.output(mandatory = True),
|
||||
"_tool": attr.label(executable = True, cfg = "host", default = Label("//tools/go_generics")),
|
||||
},
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=Q
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=Q
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=Q -suffix=New -anon
|
||||
@@ -1 +0,0 @@
|
||||
-c=c1=20 -c=z=600 -c=v=3.3 -c=s="def" -c=A=20 -c=C=100 -c=S="def" -c=T="ABC"
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=sync.Mutex -c=n=math.Uint32 -c=m=math.Uint64 -import=sync=sync -import=math=mymathpath
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=U
|
||||
@@ -1 +0,0 @@
|
||||
-t=T=Q -suffix=New
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The gVisor Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Bash "safe-mode": Treat command failures as fatal (even those that occur in
|
||||
# pipes), and treat unset variables as errors.
|
||||
set -eu -o pipefail
|
||||
|
||||
# This file will be generated as a self-extracting shell script in order to
|
||||
# eliminate the need for any runtime dependencies. The tarball at the end will
|
||||
# include the go_generics binary, as well as a subdirectory named
|
||||
# generics_tests. See the BUILD file for more information.
|
||||
declare -r temp=$(mktemp -d)
|
||||
function cleanup() {
|
||||
rm -rf "${temp}"
|
||||
}
|
||||
# trap cleanup EXIT
|
||||
|
||||
# Print message in "$1" then exit with status 1.
|
||||
function die () {
|
||||
echo "$1" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# This prints the line number of __BUNDLE__ below, that should be the last line
|
||||
# of this script. After that point, the concatenated archive will be the
|
||||
# contents.
|
||||
declare -r tgz=`awk '/^__BUNDLE__/ {print NR + 1; exit 0; }' $0`
|
||||
tail -n+"${tgz}" $0 | tar -xzv -C "${temp}"
|
||||
|
||||
# The target for the test.
|
||||
declare -r binary="$(find ${temp} -type f -a -name go_generics)"
|
||||
declare -r input_dirs="$(find ${temp} -type d -a -name generics_tests)/*"
|
||||
|
||||
# Go through all test cases.
|
||||
for f in ${input_dirs}; do
|
||||
base=$(basename "${f}")
|
||||
|
||||
# Run go_generics on the input file.
|
||||
opts=$(head -n 1 ${f}/opts.txt)
|
||||
out="${f}/output/generated.go"
|
||||
expected="${f}/output/output.go"
|
||||
${binary} ${opts} "-i=${f}/input.go" "-o=${out}" || die "go_generics failed for test case \"${base}\""
|
||||
|
||||
# Compare the outputs.
|
||||
diff ${expected} ${out}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Expected:"
|
||||
cat ${expected}
|
||||
echo "Actual:"
|
||||
cat ${out}
|
||||
die "Actual output is different from expected for test \"${base}\""
|
||||
fi
|
||||
done
|
||||
|
||||
echo "PASS"
|
||||
exit 0
|
||||
__BUNDLE__
|
||||
@@ -0,0 +1,16 @@
|
||||
load("//tools/go_generics/tests:defs.bzl", "go_generics_test")
|
||||
|
||||
go_generics_test(
|
||||
name = "all_stmts",
|
||||
inputs = ["input.go"],
|
||||
output = "output.go",
|
||||
types = {
|
||||
"T": "Q",
|
||||
},
|
||||
)
|
||||
|
||||
# @unused
|
||||
glaze_ignore = [
|
||||
"input.go",
|
||||
"output.go",
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
load("//tools/go_generics/tests:defs.bzl", "go_generics_test")
|
||||
|
||||
go_generics_test(
|
||||
name = "all_types",
|
||||
inputs = ["input.go"],
|
||||
output = "output.go",
|
||||
types = {
|
||||
"T": "Q",
|
||||
},
|
||||
)
|
||||
|
||||
# @unused
|
||||
glaze_ignore = [
|
||||
"input.go",
|
||||
"output.go",
|
||||
]
|
||||
+3
-1
@@ -14,7 +14,9 @@
|
||||
|
||||
package tests
|
||||
|
||||
import "./lib"
|
||||
import (
|
||||
"./lib"
|
||||
)
|
||||
|
||||
type T int
|
||||
|
||||
+3
-1
@@ -14,7 +14,9 @@
|
||||
|
||||
package main
|
||||
|
||||
import "./lib"
|
||||
import (
|
||||
"./lib"
|
||||
)
|
||||
|
||||
type newType struct {
|
||||
a Q
|
||||
@@ -0,0 +1,18 @@
|
||||
load("//tools/go_generics/tests:defs.bzl", "go_generics_test")
|
||||
|
||||
go_generics_test(
|
||||
name = "anon",
|
||||
anon = True,
|
||||
inputs = ["input.go"],
|
||||
output = "output.go",
|
||||
suffix = "New",
|
||||
types = {
|
||||
"T": "Q",
|
||||
},
|
||||
)
|
||||
|
||||
# @unused
|
||||
glaze_ignore = [
|
||||
"input.go",
|
||||
"output.go",
|
||||
]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user