Skip to content

Commit e5a2144

Browse files
committed
added artifacts for ai
1 parent a52f7f5 commit e5a2144

4 files changed

Lines changed: 327 additions & 15 deletions

File tree

install/ci-vm/ci-linux/ci/runCI

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
99

10+
# Enable coredump capture
11+
ulimit -c unlimited
12+
mkdir -p /tmp/coredumps
13+
echo "/tmp/coredumps/core.%e.%p" | sudo tee /proc/sys/kernel/core_pattern > /dev/null
14+
1015
if [ ! -f "$DIR/variables" ]; then
1116
# No variable file defined
1217
sudo shutdown -h now
@@ -123,10 +128,69 @@ if [ -e "${dstDir}/ccextractor" ]; then
123128
echo "=== CCExtractor Binary Version ===" >> "${logFile}"
124129
./ccextractor --version >> "${logFile}" 2>&1
125130
echo "=== End Version Info ===" >> "${logFile}"
126-
postStatus "testing" "Running tests"
131+
132+
133+
ccextractor_path="$(pwd)/ccextractor"
134+
combined_stdout="/tmp/combined_stdout.log"
135+
: > "${combined_stdout}"
136+
137+
# Create a wrapper script that tees stdout/stderr to a combined log
138+
wrapper_path="$(pwd)/ccextractor_wrapper"
139+
cat > "${wrapper_path}" << 'WRAPPER_EOF'
140+
#!/bin/bash
141+
COMBINED_LOG="/tmp/combined_stdout.log"
142+
REAL_BINARY="PLACEHOLDER_BINARY"
143+
EXIT_CODE_FILE="/tmp/.wrapper_exit_code"
144+
echo "=== TEST INVOCATION: $@ ===" >> "$COMBINED_LOG"
145+
{ "$REAL_BINARY" "$@" 2>&1; echo $? > "$EXIT_CODE_FILE"; } | tee -a "$COMBINED_LOG"
146+
exit_code=$(cat "$EXIT_CODE_FILE")
147+
echo "=== EXIT CODE: ${exit_code} ===" >> "$COMBINED_LOG"
148+
echo "" >> "$COMBINED_LOG"
149+
exit $exit_code
150+
WRAPPER_EOF
151+
sed -i "s|PLACEHOLDER_BINARY|${ccextractor_path}|" "${wrapper_path}"
152+
chmod +x "${wrapper_path}"
153+
127154
executeCommand cd ${suiteDstDir}
128-
executeCommand ${tester} --debug --entries "${testFile}" --executable "ccextractor" --tempfolder "${tempFolder}" --timeout 600 --reportfolder "${reportFolder}" --resultfolder "${resultFolder}" --samplefolder "${sampleFolder}" --method Server --url "${reportURL}"
155+
executeCommand ${tester} --debug --entries "${testFile}" --executable "${wrapper_path}" --tempfolder "${tempFolder}" --timeout 600 --reportfolder "${reportFolder}" --resultfolder "${resultFolder}" --samplefolder "${sampleFolder}" --method Server --url "${reportURL}"
156+
157+
# Upload AI artifacts to GCS
158+
gcs_bucket=$(curl -s "http://metadata/computeMetadata/v1/instance/attributes/bucket" -H "Metadata-Flavor: Google")
159+
test_id=$(curl -s "http://metadata/computeMetadata/v1/instance/attributes/testID" -H "Metadata-Flavor: Google")
160+
token=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
161+
162+
upload_artifact() {
163+
local file_path="$1"
164+
local dest_path="$2"
165+
if [ -f "$file_path" ]; then
166+
local http_code
167+
http_code=$(curl -s -X POST --data-binary @"$file_path" \
168+
-H "Authorization: Bearer $token" \
169+
-H "Content-Type: application/octet-stream" \
170+
-w "%{http_code}" \
171+
-o /dev/null \
172+
"https://storage.googleapis.com/upload/storage/v1/b/${gcs_bucket}/o?uploadType=media&name=${dest_path}")
173+
if [ -z "$http_code" ] || [ "$http_code" -ne 200 ]; then
174+
echo "GCS upload failed for ${dest_path}: HTTP ${http_code:-no_response}" >> "${logFile}"
175+
fi
176+
fi
177+
}
178+
179+
upload_artifact "$ccextractor_path" "test_artifacts/${test_id}/ccextractor"
180+
181+
# Upload combined stdout log
182+
upload_artifact "${combined_stdout}" "test_artifacts/${test_id}/combined_stdout.log"
183+
184+
# Upload coredumps if any
185+
for core_file in /tmp/coredumps/core.*; do
186+
if [ -f "$core_file" ]; then
187+
upload_artifact "$core_file" "test_artifacts/${test_id}/coredump"
188+
break
189+
fi
190+
done
191+
129192
sendLogFile
193+
upload_artifact "${logFile}" "test_artifacts/${test_id}/full_output.log"
130194
postStatus "completed" "Ran all tests"
131195

132196
sudo shutdown -h now

mod_ci/controllers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ def create_instance(compute, project, zone, test, reportURL) -> Dict:
11951195
metadata_items = [
11961196
{'key': 'startup-script', 'value': startup_script},
11971197
{'key': 'reportURL', 'value': reportURL},
1198-
{'key': 'bucket', 'value': config.get('GCS_BUCKET_NAME', '')}
1198+
{'key': 'bucket', 'value': config.get('GCS_BUCKET_NAME', '')},
1199+
{'key': 'testID', 'value': str(test.id)}
11991200
]
12001201
elif test.platform == TestPlatform.windows:
12011202
image_response = compute.images().getFromFamily(project=config.get('WINDOWS_INSTANCE_PROJECT_NAME', ''),
@@ -1217,7 +1218,8 @@ def create_instance(compute, project, zone, test, reportURL) -> Dict:
12171218
{'key': 'service_account', 'value': service_account},
12181219
{'key': 'rclone_conf', 'value': rclone_conf},
12191220
{'key': 'reportURL', 'value': reportURL},
1220-
{'key': 'bucket', 'value': config.get('GCS_BUCKET_NAME', '')}
1221+
{'key': 'bucket', 'value': config.get('GCS_BUCKET_NAME', '')},
1222+
{'key': 'testID', 'value': str(test.id)}
12211223
]
12221224
source_disk_image = image_response['selfLink']
12231225

@@ -2635,7 +2637,7 @@ def upload_log_type_request(log, test_id, repo_folder, test, request) -> bool:
26352637
uploaded_file.save(temp_path)
26362638
final_path = os.path.join(repo_folder, 'LogFiles', f"{test.id}.txt")
26372639

2638-
os.rename(temp_path, final_path)
2640+
os.replace(temp_path, final_path)
26392641
log.debug("Stored log file")
26402642
return True
26412643

@@ -2681,7 +2683,7 @@ def upload_type_request(log, test_id, repo_folder, test, request) -> bool:
26812683
results_dir = os.path.join(repo_folder, 'TestResults')
26822684
os.makedirs(results_dir, exist_ok=True)
26832685
final_path = os.path.join(results_dir, f'{file_hash}{file_extension}')
2684-
os.rename(temp_path, final_path)
2686+
os.replace(temp_path, final_path)
26852687
rto = RegressionTestOutput.query.filter(
26862688
RegressionTestOutput.id == request.form['test_file_id']).first()
26872689
result_file = TestResultFile(test.id, request.form['test_id'], rto.id, rto.correct, file_hash)

0 commit comments

Comments
 (0)