Merge branch 'tests/final-tests' of https://git.mamahaha.work/sangge/BackDoorBuster into tests/final-tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import time
|
||||
import unittest
|
||||
import shutil
|
||||
import os
|
||||
import threading
|
||||
|
||||
from detection.utils import read_file_content
|
||||
from .final_tests_util import clone_repo, Path, inject_random_backdoor
|
||||
@@ -8,6 +10,25 @@ from detection.Regexdetection import find_dangerous_functions
|
||||
from detection.GPTdetection import detectGPT
|
||||
|
||||
|
||||
def GPTdetectFileList(fileList):
|
||||
results = []
|
||||
threads = []
|
||||
for file in fileList:
|
||||
content = read_file_content(str(file))
|
||||
threads.append(threading.Thread(target=GPTThread(), args=(content, results)))
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
time.sleep(0.5)
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
return results
|
||||
|
||||
def GPTThread(content, results):
|
||||
try:
|
||||
results.append(detectGPT(content))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
class TestFinalTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.path = "./tmp/repo/"
|
||||
@@ -79,6 +100,12 @@ class TestFinalTests(unittest.TestCase):
|
||||
injected_detectedNum += 1
|
||||
injected_accurency = injected_detectedNum / self.injectedNum
|
||||
print(f"injected files accurency: {injected_accurency}")
|
||||
GPTresult = GPTdetectFileList(possibly_dangerous_file)
|
||||
for result in GPTresult:
|
||||
if len(result) > 0:
|
||||
GPTdetectedNum += 1
|
||||
print(GPTdetectedNum)
|
||||
self.assertGreaterEqual(GPTdetectedNum, detectedNum)
|
||||
|
||||
# test pickle files
|
||||
with open(self.path + "output.txt", "r") as f:
|
||||
|
||||
Reference in New Issue
Block a user