Squashed 'third_party/autocxx/' content from commit 629e8fa53
git-subtree-dir: third_party/autocxx
git-subtree-split: 629e8fa531a633164c0b52e2a3cab536d4cd0849
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: I62a03b0049f49adf029e0204639cdb5468dde1a1
diff --git a/tools/stress-test/Cargo.toml b/tools/stress-test/Cargo.toml
new file mode 100644
index 0000000..6f15e42
--- /dev/null
+++ b/tools/stress-test/Cargo.toml
@@ -0,0 +1,21 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+[package]
+name = "autocxx-stress-test"
+version = "0.22.0"
+authors = ["Adrian Taylor <adetaylor@chromium.org>"]
+edition = "2021"
+
+[dependencies]
+cxx = "1.0.54"
+autocxx = { path = "../..", version="0.22.0" }
+
+[build-dependencies]
+autocxx-build = { path = "../../gen/build", version="0.22.0" }
+miette = { version="4.3", features=["fancy"]}
diff --git a/tools/stress-test/README.md b/tools/stress-test/README.md
new file mode 100644
index 0000000..7a1801c
--- /dev/null
+++ b/tools/stress-test/README.md
@@ -0,0 +1,5 @@
+This directory contains a code example which tries to generate bindings to all the things
+in various STL headers.
+
+This currently is a long way from working, so there's a reduce.sh script in this directory
+which helps identify and minimize test cases for each new problem.
diff --git a/tools/stress-test/build.rs b/tools/stress-test/build.rs
new file mode 100644
index 0000000..bffd96f
--- /dev/null
+++ b/tools/stress-test/build.rs
@@ -0,0 +1,17 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() -> miette::Result<()> {
+ let path = std::path::PathBuf::from("src");
+ let mut b = autocxx_build::Builder::new("src/main.rs", &[&path]).build()?;
+ b.flag_if_supported("-std=c++14").compile("autocxx-stress-test");
+
+ println!("cargo:rerun-if-changed=src/main.rs");
+ println!("cargo:rerun-if-changed=src/input.h");
+ Ok(())
+}
diff --git a/tools/stress-test/reduce.sh b/tools/stress-test/reduce.sh
new file mode 100755
index 0000000..0722825
--- /dev/null
+++ b/tools/stress-test/reduce.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# Using this stress test
+# 1. cargo build
+# 2. Spot what error message appears (because something will)
+# 3. Create a new directory and cd into it
+# 4. Run this script passing the error message as an argument
+# 5. Wait (consider running tail -f nohup.out)
+# 6. Several days later, a minimized test case should appear in nohup.out.
+
+set -e
+
+PROBLEM="$1"
+SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
+TEST_CASE_DIR=$(pwd)
+
+if [ !-n "$PROBLEM" ]; then
+ echo "Specify a compile error as an argument"
+ exit -1
+fi
+
+echo "About to minimize stress test. Problem is '$PROBLEM' and script dir is '$SCRIPT_DIR'. Test case dir is $TEST_CASE_DIR"
+
+REPRO_CASE="$TEST_CASE_DIR/repro.json"
+
+pushd $SCRIPT_DIR
+touch src/main.rs
+echo Building with repro case
+AUTOCXX_REPRO_CASE=$REPRO_CASE cargo build --release || true
+echo Built.
+popd
+
+echo Building autocxx-reduce and friends
+pushd $SCRIPT_DIR/../..
+cargo build --all --release
+popd
+
+echo Starting reduction
+nohup $SCRIPT_DIR/../../target/release/autocxx-reduce --problem "$PROBLEM" -k --clang-arg=-std=c++17 --creduce-arg=--n --creduce-arg=192 repro -r "$REPRO_CASE" &
+echo Reduction underway. Consider using tail -f nohup.out.
+
diff --git a/tools/stress-test/src/input.h b/tools/stress-test/src/input.h
new file mode 100644
index 0000000..31961d6
--- /dev/null
+++ b/tools/stress-test/src/input.h
@@ -0,0 +1,17 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#pragma once
+
+#include <cstdint>
+#include <sstream>
+#include <stdint.h>
+#include <string>
+
+inline void DoNothing() {
+}
diff --git a/tools/stress-test/src/main.rs b/tools/stress-test/src/main.rs
new file mode 100644
index 0000000..94d9bc0
--- /dev/null
+++ b/tools/stress-test/src/main.rs
@@ -0,0 +1,19 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use autocxx::prelude::*;
+include_cpp! {
+ #include "input.h"
+ safety!(unsafe_ffi)
+ generate_all!()
+}
+
+fn main() {
+ ffi::DoNothing();
+ println!("Gosh, it worked.");
+}