我正在編寫一個用於持續集成和測試的python腳本,該腳本將被咬人調用。我們的單元測試使用谷歌測試框架。每個軟件組件都有一個運行配置和其他所需服務的bash腳本,並運行gtest可執行文件。 python腳本遍歷存儲庫查找bash腳本,並使用os.popen()命令調用每個腳本。從python調用seg時出錯,但從命令行正常運行
Python腳本(UnitTest.py)
#!/usr/bin/python
import os
import fnmatch
import sys
import subprocess
repository_location = '/home/actuv/workspace/eclipse/iccs/'
unit_test_script_name = 'RunUnitTests.sh'
def file_locator(repo, script_name):
# Function for determining all unit test scripts
test_location = []
for root, dirnames, filenames in os.walk(repo):
for filename in fnmatch.filter(filenames, script_name):
test_location.append(os.path.join(root))
return test_location
def run_tests(test_locations, script_name):
# Runs test scripts located at each test location
for tests in test_locations:
cmd = 'cd ' + tests + ';./' + script_name
print 'Running Unit Test at: ' + tests
os.popen(cmd)
################ MAIN ################
# Find Test Locations
script_locations = file_locator(repository_location, unit_test_script_name)
# Run tests located at each location
run_tests(script_locations)
# End of tests
sys.exit(0)
bash腳本
#!/bin/sh
echo "Running unit tests..."
# update the LD_LIBRARY_PATH to include paths to our shared libraries
# start the test server
# Run the tests
# wait to allow all processes to end before terminating the server
sleep 10s
當我從終端窗口手動運行bash腳本,它運行良好。當我使用python腳本調用bash腳本時,我在bash腳本的TestSingleClient和TestMultiClientLA行上出現了分段錯誤。
我最初有一個問題,它找不到腳本,但我意識到我需要在腳本名稱前加'./'。 – Axe
啊,我明白了。編輯... – unutbu
我還發現,當允許管道傳輸到被咬的控制檯時,stdout和stderr會引起重大問題。我打開了一個臨時文件(temp = open(temp,'w')),並將stdout = temp和stderr = temp標誌添加到Popen調用中。 – Axe