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 jobjob_device_target = "QCS6490" # target chipsettest_script_file = r"./BashTestExample.zip" # same name as the test script preparedtest_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/shecho test startingsleep 10mount -o rw,remount /# Function to create QDCResults.xml with JUnit-compatible content in /data/local/tmpcreate_junit_results() {echo '<?xml version="1.0" encoding="UTF-8"?>' > /data/local/tmp/QDCResults.xmlecho '<testsuites>' >> /data/local/tmp/QDCResults.xmlecho ' <testsuite name="QDC Test Suite" tests="1" failures="0" errors="0" skipped="0">' >> /data/local/tmp/QDCResults.xmlecho ' <testcase classname="QDC.Test" name="Test1">' >> /data/local/tmp/QDCResults.xmlecho ' </testcase>' >> /data/local/tmp/QDCResults.xmlecho ' </testsuite>' >> /data/local/tmp/QDCResults.xmlecho '</testsuites>' >> /data/local/tmp/QDCResults.xml}# Function to create log files in /data/local/tmp/QDC_logscreate_log_files() {mkdir -p /data/local/tmp/QDC_logsecho 'Log entry: Test started' > /data/local/tmp/QDC_logs/log.txtecho 'Log entry: Test completed' >> /data/local/tmp/QDC_logs/log.txt}# Call the functions to create the filescreate_junit_resultscreate_log_filesmount -o rw,remount /touch /data/local/tmp/QDCTestDone.txtecho test done