Sample - Bash Job
The following is a sample Python code for calling QDC public APIs to test using Bash script.
- Available chipsets
Bash jobs can only be used with job targets where the ChipsetCategory is IOT and the OS is Linux. To get the list of available targets, call this QDC public API.
- Artifacts limitation
| Type | Artifacts Number | Suffix |
|---|---|---|
| test package | optional | .zip |
| test script | optional | .zip |
- Sample code is similar to Monkey Job except
Section (1)part
# Section (1): preparing the parameters and submitting the job
job_device_target = "QCS6490" # target chipset
test_script_file = r"./BashTestExample.zip" # same name as the test script prepared
test_script_response = qdc_api.upload_file(public_api_client, test_script_file, ArtifactType.TESTSCRIPT)
job_target_id = qdc_api.get_target_id(public_api_client, job_device_target)
job_id = qdc_api.submit_job(public_api_client=public_api_client,
target_id=job_target_id,
job_name="Example Job",
external_job_id="ExJobId001",
job_type=JobType.AUTOMATED,
job_mode=JobMode.APPLICATION,
timeout=600,
test_framework=TestFramework.BASH,
entry_script="sh /data/local/tmp/TestContent/BashTestExample/ScriptToRun.sh",
job_artifacts=[test_script_response],
monkey_events=None,
monkey_session_timeout=None,
job_parameters=[])- Sample Test Packages
Create a file named ScriptToRun.sh, copy the following code into it, zip the file to BashTestExample.zip, and and move the zip file into the same folder as hello_qdc.py.
#!/bin/sh
echo test starting
sleep 10
mount -o rw,remount /
# Function to create QDCResults.xml with JUnit-compatible content in /data/local/tmp
create_junit_results() {
echo '<?xml version="1.0" encoding="UTF-8"?>' > /data/local/tmp/QDCResults.xml
echo '<testsuites>' >> /data/local/tmp/QDCResults.xml
echo ' <testsuite name="QDC Test Suite" tests="1" failures="0" errors="0" skipped="0">' >> /data/local/tmp/QDCResults.xml
echo ' <testcase classname="QDC.Test" name="Test1">' >> /data/local/tmp/QDCResults.xml
echo ' </testcase>' >> /data/local/tmp/QDCResults.xml
echo ' </testsuite>' >> /data/local/tmp/QDCResults.xml
echo '</testsuites>' >> /data/local/tmp/QDCResults.xml
}
# Function to create log files in /data/local/tmp/QDC_logs
create_log_files() {
mkdir -p /data/local/tmp/QDC_logs
echo 'Log entry: Test started' > /data/local/tmp/QDC_logs/log.txt
echo 'Log entry: Test completed' >> /data/local/tmp/QDC_logs/log.txt
}
# Call the functions to create the files
create_junit_results
create_log_files
mount -o rw,remount /
touch /data/local/tmp/QDCTestDone.txt
echo test done