Harini0924 643a2080ec
[llvm-lit] Fix error in compiler-rt tests when using lit internal shell with env (#102069)
When running tests in compiler-rt using the lit internal shell with the
following command:
```
LIT_USE_INTERNAL_SHELL=1 ninja check-compiler-rt
```
one common error that occurs is:
```
'XRAY_OPTIONS=patch_premain=false:verbosity=1': command not found
```
This error, along with over 50 similar "environment variable not found"
errors, appears across 35 files in complier-rt. These errors happen
because the environment variables are not being set correctly when the
internal shell is used, leading to commands failing due to unrecognized
environment variables.

This patch addresses the issue by using the `env` command to properly
set the environment variables before running the tests. By explicitly
setting the environment variables through `env`, the internal shell can
correctly interpret and apply them, allowing the tests to pass.
fixes: #102395 
[link to
RFC](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179)
2024-08-13 15:13:51 -07:00

43 lines
1.1 KiB
C++

// Check that we can get the first function argument logged
// using a custom logging function.
//
// RUN: %clangxx_xray -std=c++11 %s -o %t
// RUN: rm -f arg1-logger-*
// RUN: env XRAY_OPTIONS="patch_premain=true verbosity=1 xray_mode=xray-basic \
// RUN: xray_logfile_base=arg1-logger-" %run %t 2>&1 | FileCheck %s
//
// After all that, clean up the XRay log file.
//
// RUN: rm -f arg1-logger-*
// REQUIRES: target={{(aarch64|x86_64)-.*}}
#include "xray/xray_interface.h"
#include <cinttypes>
#include <cstdio>
void arg1logger(int32_t fn, XRayEntryType t, uint64_t a1) {
printf("Arg1: %" PRIx64 ", XRayEntryType %u\n", a1, t);
}
[[clang::xray_always_instrument, clang::xray_log_args(1)]] void foo(void *) {}
int main() {
// CHECK: XRay: Log file in 'arg1-logger-{{.*}}'
__xray_set_handler_arg1(arg1logger);
foo(nullptr);
// CHECK: Arg1: 0, XRayEntryType 3
__xray_remove_handler_arg1();
foo((void *) 0xBADC0DE);
// nothing expected to see here
__xray_set_handler_arg1(arg1logger);
foo((void *) 0xDEADBEEFCAFE);
// CHECK-NEXT: Arg1: deadbeefcafe, XRayEntryType 3
foo((void *) -1);
// CHECK-NEXT: Arg1: ffffffffffffffff, XRayEntryType 3
}