Skip to content

Commit

Permalink
upload mugen_riscv and qemu_test
Browse files Browse the repository at this point in the history
  • Loading branch information
KotorinMinami committed Apr 27, 2023
1 parent a8c9f59 commit 50d9a3c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
6 changes: 6 additions & 0 deletions mugen_riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def GenJson(self,test_res):
parser.add_argument('-a','--analyze',action='store_true',help='Analyze missing testcases')
parser.add_argument('-g','--generate',action='store_true',help='Generate testsuite json after running test')
parser.add_argument('-f',metavar='test_suite',help='Specify testsuite',dest='test_suite',default=None)
parser.add_argument('-o','--output_dir',type=str,default='',help='Specity the dir to store the logs')
parser.add_argument('-x',action='store_true',help='-x parameter')
parser.add_argument('--addDisk',action='store_true')
parser.add_argument('--multiMachine',action='store_true')
Expand Down Expand Up @@ -282,4 +283,9 @@ def GenJson(self,test_res):
if args.generate == True:
gen = SuiteGenerator()
gen.GenJson(test_res)
if args.output_dir != '':
os.system('ls logs_failed && /bin/cp -rf logs '+args.output_dir)
os.system('ls logs_failed && /bin/cp -rf logs_failed '+args.output_dir)
os.system('ls suite2cases_out && /bin/cp -rf suite2cases_out '+args.output_dir)
os.system('ls exec.log && /bin/cp -rf exec.log '+args.output_dir)

78 changes: 61 additions & 17 deletions qemu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import paramiko
from mugen_riscv import TestEnv,TestTarget
from queue import Queue
from libs.locallibs import sftp,ssh_cmd
from libs.locallibs import sftp,ssh_cmd,mugen_log
from threading import Thread
import threading
import subprocess
Expand All @@ -20,7 +20,7 @@ def ssh_exec(qemuVM,cmd,timeout=5):
exitcode,output = ssh_cmd.pssh_cmd(conn,cmd)
ssh_cmd.pssh_close(conn)
except :
print("ssh execute "+cmd+" failed")
mugen_log.logging("error" , "ssh execute "+cmd+" failed")
exitcode , output = None , None
return exitcode,output

Expand Down Expand Up @@ -54,6 +54,20 @@ def findAvalPort(num=1):
port += 1
return port_list

def copydown(qemuVM , copydir , copyfile='' , localdir = '.',timeout=5) -> bool :
if copyfile == '':
target = qemuVM.workingDir+copydir
else:
target = os.path.join(qemuVM.workingDir+copydir,copyfile)
os.system('ls '+localdir+' || mkdir '+localdir)
t_end = time.time() + timeout
while time.time() < t_end:
if os.path.exists(target):
mugen_log.logging("info" , "start to copy "+target+' to '+localdir)
os.system('/bin/cp -rf '+target+' '+localdir)
return True
return False

class Dispatcher(Thread):
def __init__(self,qemuVM,targetQueue,tapQueue,br_ip,step,initTarget=None):
super(Dispatcher,self).__init__()
Expand All @@ -77,6 +91,7 @@ def run(self):
self.targetQueue.put(self.initTarget)
else:
self.qemuVM.start(disk=self.initTarget[1],machine=self.initTarget[2],tap_number=self.initTarget[3]+1,taplist=[self.tapQueue.get() for i in range(self.initTarget[3]+1)])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
for i in range(1 , self.initTarget[2]):
self.attachVM.append(QemuVM(id= i*self.step+self.qemuVM.id, vcpu=self.qemuVM.vcpu , memory=self.qemuVM.memory,
Expand Down Expand Up @@ -110,6 +125,7 @@ def run(self):
self.targetQueue.put(self.initTarget)
else:
self.qemuVM.start(disk=self.initTarget[1],machine=self.initTarget[2],tap_number=1,taplist=[self.tapQueue.get()])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
ports = findAvalPort(self.initTarget[2]-1)
print(ports)
Expand Down Expand Up @@ -146,6 +162,7 @@ def run(self):
self.targetQueue.put(self.initTarget)
else:
self.qemuVM.start(disk=self.initTarget[1],machine=self.initTarget[2],tap_number=self.initTarget[3],taplist=[self.tapQueue.get() for i in range(tapnum)])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
try:
self.qemuVM.runTest(self.initTarget[0])
Expand All @@ -158,6 +175,7 @@ def run(self):
self.tapQueue.put(self.qemuVM.tapls.pop())
else:
self.qemuVM.start(disk=self.initTarget[1])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
try:
self.qemuVM.runTest(self.initTarget[0])
Expand All @@ -180,6 +198,7 @@ def run(self):
self.targetQueue.put(target)
else:
self.qemuVM.start(disk=target[1],machine=target[2],tap_number=target[3]+1,taplist=[self.tapQueue.get() for i in range(target[3]+1)])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
ports = findAvalPort(target[2]-1)
print(ports)
Expand Down Expand Up @@ -214,6 +233,7 @@ def run(self):
self.targetQueue.put(target)
else:
self.qemuVM.start(disk=target[1],machine=target[2],tap_number=1,taplist=[self.tapQueue.get()])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
for i in range(1 , target[2]):
self.attachVM.append(QemuVM(id= i*self.step+self.qemuVM.id, vcpu=self.qemuVM.vcpu , memory=self.qemuVM.memory,
Expand Down Expand Up @@ -247,6 +267,7 @@ def run(self):
self.targetQueue.put(target)
else:
self.qemuVM.start(disk=target[1],machine=target[2],tap_number=target[3],taplist=[self.tapQueue.get() for i in range(tapnum)])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
try:
self.qemuVM.runTest(target[0])
Expand All @@ -259,6 +280,7 @@ def run(self):
self.tapQueue.put(self.qemuVM.tapls.pop())
else:
self.qemuVM.start(target[1])
self.qemuVM.sharedReady()
self.qemuVM.waitReady()
try:
self.qemuVM.runTest(target[0])
Expand All @@ -270,7 +292,7 @@ def run(self):

class QemuVM(object):
def __init__(self, vcpu,memory,workingDir,bkfile ,kernel,bios,id=1,port=12055,user='root',password='openEuler12#$',
path='/root/GitRepo/mugen-riscv' , restore=True, runArgs=''):
path='/root/GitRepo/mugen-riscv' , restore=True, runArgs='',output=''):
self.id = id
self.port , self.ip , self.user , self.password = port , '127.0.0.1' , user , password
self.vcpu , self.memory= vcpu , memory
Expand All @@ -282,8 +304,10 @@ def __init__(self, vcpu,memory,workingDir,bkfile ,kernel,bios,id=1,port=12055,us
self.runArgs = runArgs
self.mac = id+1
self.tapls = []
if self.workingDir[-1] != '/':
self.workingDir += '/'
self.output = output
if workingDir[-1] != '/':
workingDir += '/'


def start(self , disk=1 , machine=1 , tap_number=0 , taplist=[]):
self.tapls = taplist
Expand Down Expand Up @@ -334,8 +358,11 @@ def start(self , disk=1 , machine=1 , tap_number=0 , taplist=[]):
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-device,rng=rng0 \
-device virtio-blk-device,drive=hd0 \
-device qemu-xhci -usb -device usb-kbd -device usb-tablet -device usb-audio,audiodev=snd0 \
-append 'root=/dev/vda1 rw console=ttyS0 swiotlb=1 loglevel=3 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem="+str(memory_append)+"M earlycon' "
-device qemu-xhci -usb -device usb-kbd -device usb-tablet -device usb-audio,audiodev=snd0 "

if self.output != '':
shared_path=self.workingDir+self.output+str(self.id)
cmd += "-virtfs local,id=test,path="+shared_path+",security_model=none,mount_tag=test "

if disk > 1:
for i in range(1 ,disk):
Expand All @@ -354,6 +381,12 @@ def start(self , disk=1 , machine=1 , tap_number=0 , taplist=[]):
cmd += "-netdev user,id=usernet,hostfwd=tcp::"+str(ssh_port)+"-:22 -device virtio-net-device,netdev=usernet,mac=52:54:00:11:45:{:0>2d}".format(self.mac)
self.process = subprocess.Popen(args=cmd,stderr=subprocess.PIPE,stdout=subprocess.PIPE,stdin=subprocess.PIPE,encoding='utf-8',shell=True)

def sharedReady(self):
if self.output != '':
while not os.path.exists(self.workingDir+self.output+str(self.id)+'/shared_ready'):
time.sleep(5)
os.system('rm -rf '+self.workingDir+self.output+'/shared_ready')

def waitReady(self):
conn = 519
while conn == 519:
Expand Down Expand Up @@ -384,14 +417,18 @@ def conftap(self , br_ip , tapnode=None):


def runTest(self,testsuite):
print(ssh_exec(self,'cd '+self.path+' \n echo \''+testsuite+'\' > list_temp \n python3 mugen_riscv.py -l list_temp '+self.runArgs,timeout=60)[1])
if lstat(self,self.path+'/logs_failed') is not None:
sftp_get(self,self.path+'/logs_failed','',self.workingDir)
if lstat(self,self.path+'/logs') is not None:
sftp_get(self,self.path+'/logs','',self.workingDir)
if lstat(self , self.path+'/suite2cases_out') is not None:
sftp_get(self,self.path+'/suite2cases_out','',self.workingDir)
sftp_get(self,self.path,'exec.log',self.workingDir+'exec_log/'+testsuite)
print(ssh_exec(self,'cd '+self.path+' \n echo \''+testsuite+'\' > list_temp \n python3 mugen_riscv.py -l list_temp '+self.runArgs+' \n poweroff',timeout=60)[1])
if not copydown(self , self.workingDir+self.output+'/logs_failed' , '' , self.workingDir):
if lstat(self,self.path+'/logs_failed') is not None:
sftp_get(self,self.path+'/logs_failed','',self.workingDir)
if not copydown(self , self.workingDir+self.output+'/logs' , '' , self.workingDir):
if lstat(self,self.path+'/logs') is not None:
sftp_get(self,self.path+'/logs','',self.workingDir)
if not copydown(self , self.workingDir+self.output+'/suite2cases_out' , '' , self.workingDir):
if lstat(self,self.path+'/suite2cases_out') is not None:
sftp_get(self,self.path+'/suite2cases_out','',self.workingDir)
if not copydown(self , self.workingDir+self.output+'/exec.log' , '' , self.workingDir+'exec_log/'+testsuite):
sftp_get(self,self.path,'/exec.log',self.workingDir+'exec_log/'+testsuite)


def isBroken(self):
Expand Down Expand Up @@ -452,7 +489,7 @@ def destroy(self):
# set default values
threadNum = 1
coreNum , memSize = 4 , 4
runningArg = ''
runningArg = ' -o /root/shared'
mugenNative , generateJson , preImg , genList = False , False , False , False
list_file , workingDir , bkFile , orgDrive , mugenPath = None , None , None , None , None
kernel , bios = None , None
Expand Down Expand Up @@ -646,6 +683,13 @@ def destroy(self):
os.system('rm -f ./temp.txt')
finally:
ssh_exec(preVM , 'rm -f /root/temp.txt')
file=ssh_exec(preVM , "if test -f /etc/rc.local;then echo '/etc/rc.local'; elif test -f /etc/rc.d/rc.local; then echo '/etc/rc.d/rc.local'; else ls /etc/rc.d || mkdir /etc/rc.d; touch /etc/rc.d/rc.local; fi")[1]
ssh_exec(preVM , 'echo "ls /root/shared || mkdir /root/shared" >> '+file)
ssh_exec(preVM , 'echo "rm -rf /root/shared/*" >> '+file)
ssh_exec(preVM , 'echo "mount -t 9p -o trans=virtio,access=any test /root/shared" >> '+file)
ssh_exec(preVM , 'echo "chmod 1777 /root/shared" >> '+file)
ssh_exec(preVM , 'echo "touch /root/shared/shared_ready" >> '+file)
ssh_exec(preVM , 'chmod a+x '+file)

if genList is True:
ssh_exec(preVM,'dnf list | grep -E \'riscv64|noarch\' > pkgs.txt',timeout=120)
Expand Down Expand Up @@ -685,7 +729,7 @@ def destroy(self):
user=user , password=password,
kernel=kernel , bios=bios,
workingDir=workingDir , bkfile=bkFile , path=mugenPath,
runArgs=runningArg))
runArgs=runningArg , output='shared'))
targetQueue = Queue()
for target in test_target.test_list:
jsondata = json.loads(open('suite2cases/'+target+'.json','r').read())
Expand Down

0 comments on commit 50d9a3c

Please sign in to comment.