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

Add Invocation Script #14

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# rusttest-to-dg

Converts `rustc` testcases into dejagnu testcases for `gccrs`

# Usage

This tool was invoked by the script [run](./run.sh). Furthermore, we need the rustc and gccrs source code to be downloaded on the system. And add their paths to the environment variables `GCCRS_PATH`, `RUST_PATH` and `RUSTTEST_TO_DG_PATH`

```bash
export GCCRS_PATH=/path/to/gccrs
export RUST_PATH=/path/to/rust
export RUSTTEST_TO_DG_PATH=/path/to/rusttest-to-dg
```

Then, simply run the script [run](./run.sh)

```bash
bash run.sh
```
85 changes: 85 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

set -e

# if GCCRS_PATH is set
if [ -z "$GCCRS_PATH" ]; then
echo "Error: GCCRS_PATH environment variable is not set."
echo -e "Please set it using the command:\n\texport GCCRS_PATH=/path/to/gccrs"
exit 1
fi

# if RUST_PATH is set
if [ -z "$RUST_PATH" ]; then
echo "Error: RUST_PATH environment variable is not set."
echo -e "Please set it using the command:\n\texport RUST_PATH=/path/to/rust"
exit 1
fi

# check for rusttest-to-dg path
if [ -z "$RUSTTEST_TO_DG_PATH" ]; then
echo "Error: RUSTTEST_TO_DG_PATH environment variable is not set."
echo -e "Please set it using the command:\n\texport RUSTTEST_TO_DG_PATH=/path/to/rusttest-to-dg"
exit 1
fi

echo "GCCRS_PATH: $GCCRS_PATH"
echo "RUST_PATH: $RUST_PATH"
echo "RUSTTEST_TO_DG_PATH: $RUSTTEST_TO_DG_PATH"

# Installing rusttest-to-dg
cd "$RUSTTEST_TO_DG_PATH"
echo -e "\nInstalling rusttest-to-dg\n"
cargo install --path .
echo -e "\nInstalled rusttest-to-dg\n"


# Check if the ui directory exists and remove it if it does
if [ -d "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui" ]; then
echo "Removing existing ui directory at $GCCRS_PATH/gcc/testsuite/rust/rustc/ui"
rm -rf "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui"
fi



# Copying the RUST_PATH/tests/ui to GCCRS_PATH/gcc/testsuite/rust/rustc
echo -e "Copying tests from $RUST_PATH/tests/ui to $GCCRS_PATH/gcc/testsuite/rust/rustc"
cp -r "$RUST_PATH"/tests/ui "$GCCRS_PATH"/gcc/testsuite/rust/rustc
echo -e "Copied $RUST_PATH/tests/ui tests to $GCCRS_PATH/gcc/testsuite/rust/rustc/ui"
cd "$GCCRS_PATH"/gcc/testsuite/rust/rustc/ui

process_files() {
# Recursively process rust files
for file in "$1"/*.rs; do
if [[ -f "$file" ]]; then
base_name="${file%.rs}"
stderr_file="${base_name}.stderr"
output_file="${base_name}_dg.rs"

# if we have `.stderr` file
if [[ -f "$stderr_file" ]]; then
rusttest-to-dg "$file" --stderr "$stderr_file" > "$output_file"
else
rusttest-to-dg "$file" > "$output_file"
fi
mv "$output_file" "$file"
fi
done

# Recursively process subdirectories
for dir in "$1"/*/; do
if [[ -d "$dir" ]]; then
process_files "$dir"
fi
done
}

echo -e "Converting rustc source files to DejaGnu format..."
process_files "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui/"

# Remove all files that don't end with .rs extension in the ui directory
echo "Removing non-.rs files in $GCCRS_PATH/gcc/testsuite/rust/rustc/ui"
find "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui" -type f ! -name '*.rs' -exec rm -f {} +
echo "Removed non-.rs files in $GCCRS_PATH/gcc/testsuite/rust/rustc/ui"

echo -e "Processing complete."
7 changes: 3 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use {
pub struct Arguments {
/// The rust source file to convert into `DejaGnu` format
#[arg(
short = 'f',
long = "file",
// positional argument
value_name = "FILE",
help = "The rust source file to convert into DejaGnu format"
)]
Expand Down Expand Up @@ -60,14 +59,14 @@ mod tests {

#[test]
fn test_required_argument_file() {
let args = Arguments::parse_from(["test", "-f", "test.rs"]);
let args = Arguments::parse_from(["test", "test.rs"]);
assert_eq!(args.source_file, path::PathBuf::from("test.rs"));
assert_eq!(args.stderr_file, None);
}

#[test]
fn test_optional_argument_file() {
let args = Arguments::parse_from(["test", "-f", "test.rs", "-e", "test.stderr"]);
let args = Arguments::parse_from(["test", "test.rs", "-e", "test.stderr"]);
assert_eq!(args.source_file, path::PathBuf::from("test.rs"));
assert_eq!(args.stderr_file, Some(path::PathBuf::from("test.stderr")));
}
Expand Down
Loading