Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 8c85bae

Browse files
authored
Simple e2e testing for nitro binary file (#95)
* Add bash script test for linux * add test script for mac * Add bat script test for windows * Integrate run e2e testing nitro to CI * Update CI trigger by including .github/scripts/** --------- Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 6298888 commit 8c85bae

File tree

3 files changed

+244
-4
lines changed

3 files changed

+244
-4
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
## Example run command
4+
# ./linux-and-mac.sh './jan/plugins/@janhq/inference-plugin/dist/nitro/nitro_mac_arm64' https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/resolve/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf
5+
6+
# Check for required arguments
7+
if [[ $# -ne 2 ]]; then
8+
echo "Usage: $0 <path_to_binary> <url_to_download>"
9+
exit 1
10+
fi
11+
12+
rm /tmp/response1.log /tmp/response2.log /tmp/nitro.log
13+
14+
BINARY_PATH=$1
15+
DOWNLOAD_URL=$2
16+
17+
# Start the binary file
18+
"$BINARY_PATH" > /tmp/nitro.log 2>&1 &
19+
20+
# Get the process id of the binary file
21+
pid=$!
22+
23+
if ! ps -p $pid > /dev/null; then
24+
echo "nitro failed to start. Logs:"
25+
cat /tmp/nitro.log
26+
exit 1
27+
fi
28+
29+
# Wait for a few seconds to let the server start
30+
sleep 5
31+
32+
33+
34+
# Check if /tmp/testmodel exists, if not, download it
35+
if [[ ! -f "/tmp/testmodel" ]]; then
36+
wget $DOWNLOAD_URL -O /tmp/testmodel
37+
fi
38+
39+
# Run the curl commands
40+
response1=$(curl -o /tmp/response1.log -s -w "%{http_code}" --location 'http://localhost:3928/inferences/llamacpp/loadModel' \
41+
--header 'Content-Type: application/json' \
42+
--data '{
43+
"llama_model_path": "/tmp/testmodel",
44+
"ctx_len": 2048,
45+
"ngl": 32,
46+
"embedding": false
47+
}' 2>&1)
48+
49+
response2=$(curl -o /tmp/response2.log -s -w "%{http_code}" --location 'http://localhost:3928/inferences/llamacpp/chat_completion' \
50+
--header 'Content-Type: application/json' \
51+
--header 'Accept: text/event-stream' \
52+
--header 'Access-Control-Allow-Origin: *' \
53+
--data '{
54+
"messages": [
55+
{"content": "Hello there", "role": "assistant"},
56+
{"content": "Write a long and sad story for me", "role": "user"}
57+
],
58+
"stream": true,
59+
"model": "gpt-3.5-turbo",
60+
"max_tokens": 2048,
61+
"stop": ["hello"],
62+
"frequency_penalty": 0,
63+
"presence_penalty": 0,
64+
"temperature": 0.7
65+
}' 2>&1
66+
)
67+
68+
error_occurred=0
69+
if [[ "$response1" -ne 200 ]]; then
70+
echo "The first curl command failed with status code: $response1"
71+
cat /tmp/response1.log
72+
error_occurred=1
73+
fi
74+
75+
if [[ "$response2" -ne 200 ]]; then
76+
echo "The second curl command failed with status code: $response2"
77+
cat /tmp/response2.log
78+
error_occurred=1
79+
fi
80+
81+
if [[ "$error_occurred" -eq 1 ]]; then
82+
echo "Nitro test run failed!!!!!!!!!!!!!!!!!!!!!!"
83+
echo "Nitro Error Logs:"
84+
cat /tmp/nitro.log
85+
kill $pid
86+
exit 1
87+
fi
88+
89+
echo "----------------------"
90+
echo "Log load model:"
91+
cat /tmp/response1.log
92+
93+
echo "----------------------"
94+
echo "Log run test:"
95+
cat /tmp/response2.log
96+
97+
98+
echo "Nitro test run successfully!"
99+
100+
# Kill the server process
101+
kill $pid
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
@echo off
2+
3+
set "TEMP=C:\Users\%UserName%\AppData\Local\Temp"
4+
set "MODEL_PATH=%TEMP%\testmodel"
5+
6+
rem Check for required arguments
7+
if "%~2"=="" (
8+
echo Usage: %~0 ^<path_to_binary^> ^<url_to_download^>
9+
exit /b 1
10+
)
11+
12+
set "BINARY_PATH=%~1"
13+
set "DOWNLOAD_URL=%~2"
14+
15+
for %%i in ("%BINARY_PATH%") do set "BINARY_NAME=%%~nxi"
16+
17+
echo BINARY_NAME=%BINARY_NAME%
18+
19+
del %TEMP%\response1.log 2>nul
20+
del %TEMP%\response2.log 2>nul
21+
del %TEMP%\nitro.log 2>nul
22+
23+
rem Start the binary file
24+
start /B "" "%BINARY_PATH%" > %TEMP%\nitro.log 2>&1
25+
26+
ping -n 6 127.0.0.1 > nul
27+
28+
rem Capture the PID of the started process with "nitro" in its name
29+
for /f "tokens=2" %%a in ('tasklist /fi "imagename eq %BINARY_NAME%" /fo list ^| findstr /B "PID:"') do (
30+
set "pid=%%a"
31+
)
32+
33+
echo pid=%pid%
34+
35+
if not defined pid (
36+
echo nitro failed to start. Logs:
37+
type %TEMP%\nitro.log
38+
exit /b 1
39+
)
40+
41+
rem Wait for a few seconds to let the server start
42+
43+
rem Check if %TEMP%\testmodel exists, if not, download it
44+
if not exist "%MODEL_PATH%" (
45+
bitsadmin.exe /transfer "DownloadTestModel" %DOWNLOAD_URL% "%MODEL_PATH%"
46+
)
47+
48+
rem Define JSON strings for curl data
49+
call set "MODEL_PATH_STRING=%%MODEL_PATH:\=\\%%"
50+
set "curl_data1={\"llama_model_path\":\"%MODEL_PATH_STRING%\"}"
51+
set "curl_data2={\"messages\":[{\"content\":\"Hello there\",\"role\":\"assistant\"},{\"content\":\"Write a long and sad story for me\",\"role\":\"user\"}],\"stream\":true,\"model\":\"gpt-3.5-turbo\",\"max_tokens\":2048,\"stop\":[\"hello\"],\"frequency_penalty\":0,\"presence_penalty\":0,\"temperature\":0.7}"
52+
53+
rem Print the values of curl_data1 and curl_data2 for debugging
54+
echo curl_data1=%curl_data1%
55+
echo curl_data2=%curl_data2%
56+
57+
rem Run the curl commands and capture the status code
58+
curl.exe -o %TEMP%\response1.log -s -w "%%{http_code}" --location "http://localhost:3928/inferences/llamacpp/loadModel" --header "Content-Type: application/json" --data "%curl_data1%" > %TEMP%\response1_code.log 2>&1
59+
60+
curl.exe -o %TEMP%\response2.log -s -w "%%{http_code}" --location "http://localhost:3928/inferences/llamacpp/chat_completion" ^
61+
--header "Content-Type: application/json" ^
62+
--header "Accept: text/event-stream" ^
63+
--header "Access-Control-Allow-Origin: *" ^
64+
--data "%curl_data2%" > %TEMP%\response2_code.log 2>&1
65+
66+
set "error_occurred=0"
67+
68+
rem Read the status codes from the log files
69+
for /f %%a in (%TEMP%\response1_code.log) do set "response1=%%a"
70+
for /f %%a in (%TEMP%\response2_code.log) do set "response2=%%a"
71+
72+
if "%response1%" neq "200" (
73+
echo The first curl command failed with status code: %response1%
74+
type %TEMP%\response1.log
75+
set "error_occurred=1"
76+
)
77+
78+
if "%response2%" neq "200" (
79+
echo The second curl command failed with status code: %response2%
80+
type %TEMP%\response2.log
81+
set "error_occurred=1"
82+
)
83+
84+
if "%error_occurred%"=="1" (
85+
echo Nitro test run failed!!!!!!!!!!!!!!!!!!!!!!
86+
echo Nitro Error Logs:
87+
type %TEMP%\nitro.log
88+
taskkill /f /pid %pid%
89+
exit /b 1
90+
)
91+
92+
93+
echo ----------------------
94+
echo Log load model:
95+
type %TEMP%\response1.log
96+
97+
echo ----------------------
98+
echo "Log run test:"
99+
type %TEMP%\response2.log
100+
101+
echo Nitro test run successfully!
102+
103+
rem Kill the server process
104+
taskkill /f /pid %pid%

.github/workflows/build.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ on:
55
branches:
66
- main
77
tags: ['v*.*.*']
8-
paths: ['.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
8+
paths: ['.github/scripts/**','.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
99
pull_request:
1010
types: [opened, synchronize, reopened]
11-
paths: ['**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
11+
paths: ['.github/scripts/**','.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
1212

1313
env:
1414
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
15+
MODEL_URL: https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/resolve/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf
1516

1617
jobs:
1718
create-draft-release:
@@ -72,6 +73,12 @@ jobs:
7273
run: |
7374
mkdir -p nitro
7475
cp build/nitro nitro/
76+
77+
# run e2e testing
78+
cd nitro
79+
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
80+
cd ..
81+
7582
zip -r nitro.zip nitro
7683
7784
- uses: actions/upload-release-asset@v1.0.1
@@ -117,6 +124,12 @@ jobs:
117124
run: |
118125
mkdir -p nitro
119126
cp build/nitro nitro/
127+
128+
# run e2e testing
129+
cd nitro
130+
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
131+
cd ..
132+
120133
zip -r nitro.zip nitro
121134
122135
- uses: actions/upload-release-asset@v1.0.1
@@ -164,6 +177,12 @@ jobs:
164177
mkdir -p nitro
165178
cp llama.cpp/ggml-metal.metal nitro/
166179
cp build/nitro nitro/
180+
181+
# run e2e testing
182+
cd nitro
183+
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
184+
cd ..
185+
167186
zip -r nitro.zip nitro
168187
169188
- uses: actions/upload-release-asset@v1.0.1
@@ -209,6 +228,12 @@ jobs:
209228
run: |
210229
mkdir -p nitro
211230
cp build/nitro nitro/
231+
232+
# run e2e testing
233+
cd nitro
234+
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
235+
cd ..
236+
212237
zip -r nitro.zip nitro
213238
214239
- uses: actions/upload-release-asset@v1.0.1
@@ -278,6 +303,11 @@ jobs:
278303
robocopy build\bin\Release .\build\Release llama.dll
279304
robocopy ext_libs .\build\Release libcrypto-3-x64.dll
280305
robocopy ext_libs .\build\Release libssl-3-x64.dll
306+
307+
cd .\build\Release
308+
..\..\.github\scripts\e2e-test-windows.bat .\nitro.exe ${{ env.MODEL_URL }}
309+
cd ..\..
310+
281311
7z a nitro.zip .\build\Release\*
282312
283313
- uses: actions/upload-release-asset@v1.0.1
@@ -287,7 +317,7 @@ jobs:
287317
with:
288318
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
289319
asset_path: ./nitro.zip
290-
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64-${{ matrix.build }}.zip
320+
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64.zip
291321
asset_content_type: application/zip
292322

293323
windows-amd64-cuda-build:
@@ -338,6 +368,11 @@ jobs:
338368
robocopy build\bin\Release .\build\Release llama.dll
339369
robocopy ext_libs .\build\Release libcrypto-3-x64.dll
340370
robocopy ext_libs .\build\Release libssl-3-x64.dll
371+
372+
cd .\build\Release
373+
..\..\.github\scripts\e2e-test-windows.bat .\nitro.exe ${{ env.MODEL_URL }}
374+
cd ..\..
375+
341376
7z a nitro.zip .\build\Release\*
342377
343378
- uses: actions/upload-release-asset@v1.0.1
@@ -347,7 +382,7 @@ jobs:
347382
with:
348383
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
349384
asset_path: ./nitro.zip
350-
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64-${{ matrix.build }}-cu${{ matrix.cuda }}.zip
385+
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64-cuda.zip
351386
asset_content_type: application/zip
352387

353388
update_release_draft:

0 commit comments

Comments
 (0)