From 2826f720b700aa9850c476dc330b6ef28bf084c0 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 9 Feb 2022 20:46:52 +0800 Subject: [PATCH] feat: test of ss and ssr --- demo.py | 11 +++---- test.py | 66 +++++++++++++++++++++---------------- test/ShadowsocksR.py | 1 - test/docker/shadowsocks.py | 2 ++ test/docker/shadowsocksr.py | 3 ++ test/docker/sip003.py | 1 + 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/demo.py b/demo.py index d6d94e1..f83a2a3 100644 --- a/demo.py +++ b/demo.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + import time import socket import requests @@ -28,10 +31,6 @@ testInfo = { } print("start") - -print(dir(Builder)) -print(dir(Checker)) - print(testInfo) task = Builder.build(testInfo, '/tmp/ProxyC') print(task) @@ -40,7 +39,7 @@ if Builder.check(task) == False: print("error exit") Builder.destroy(task) else: - print("test with gstatic") + print("http check") health, delay = Checker.httpCheck(task['port']) print("health = " + str(health)) if delay < 0: @@ -48,4 +47,4 @@ else: else: print("delay = " + format(delay, '.2f') + 'ms') Builder.destroy(task) - print("stop") + print("done") diff --git a/test.py b/test.py index 595d280..8fbf9e6 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,7 @@ #!/usr/bin/python # -*- coding:utf-8 -*- +import sys import time import subprocess @@ -8,34 +9,43 @@ import test as Tester import ProxyBuilder as Builder import ProxyChecker as Checker -# print(dir(Tester)) +defaultPort = 10808 +defaultPasswd = 'dnomd343' -data = Tester.Shadowsocks(1081, 'dnomd343') -# data = Tester.ShadowsocksR(1081, 'dnomd343') +def startTest(testList): + for field in testList: + serverProcess = subprocess.Popen( + field['serverCommand'], + stdout = subprocess.DEVNULL, + stderr = subprocess.DEVNULL) + time.sleep(0.1) # 等待进程启动 + if serverProcess.poll() != None: # 服务端启动失败 + print("server unexpected exit") + continue + print(field['caption'] + ' => ', end = '') + client = Builder.build(field['proxyInfo'], '/tmp/ProxyC') + time.sleep(0.5) # 等待初始化完成 + if not Builder.check(client): + print("client unexpected exit") # 客户端启动失败 + else: + print(format(Checker.httpPing(client['port']), '.2f') + 'ms') + Builder.destroy(client) # 关闭客户端 + time.sleep(0.1) + serverProcess.terminate() # 关闭服务端 + time.sleep(0.1) + print() -# for field in data: -# print(field['proxyInfo']) -# print(field['serverCommand']) -# print('') +if len(sys.argv) <= 1: + print("no param") + sys.exit(0) -for field in data: - serverProcess = subprocess.Popen( - field['serverCommand'], - stdout = subprocess.DEVNULL, - stderr = subprocess.DEVNULL) - time.sleep(0.1) # 等待进程启动 - if serverProcess.poll() != None: # 服务端启动失败 - print("server unexpected exit") - continue - print(field['caption'] + ' => ', end = '') - client = Builder.build(field['proxyInfo'], '/tmp/ProxyC') - time.sleep(0.5) # 等待初始化完成 - if not Builder.check(client): - print("client unexpected exit") # 客户端启动失败 - else: - print(format(Checker.httpPing(client['port']), '.2f') + 'ms') - Builder.destroy(client) # 关闭客户端 - time.sleep(0.1) - serverProcess.terminate() # 关闭服务端 - time.sleep(0.1) - print() +testName = sys.argv[1] +if testName == 'ss': + testList = Tester.Shadowsocks(defaultPort, defaultPasswd) +elif testName == 'ssr': + testList = Tester.ShadowsocksR(defaultPort, defaultPasswd) +else: + print("unknown test name") + sys.exit(1) + +startTest(testList) diff --git a/test/ShadowsocksR.py b/test/ShadowsocksR.py index 75dbf7a..ba34f99 100644 --- a/test/ShadowsocksR.py +++ b/test/ShadowsocksR.py @@ -1,7 +1,6 @@ #!/usr/bin/python # -*- coding:utf-8 -*- - ssrMethodList = [ "aes-128-cfb", "aes-192-cfb", diff --git a/test/docker/shadowsocks.py b/test/docker/shadowsocks.py index f48fc5e..ef1a8e1 100644 --- a/test/docker/shadowsocks.py +++ b/test/docker/shadowsocks.py @@ -1,4 +1,6 @@ #!/usr/bin/python +# -*- coding:utf-8 -*- + method_list = { "ss-python": [ "aes-128-gcm", diff --git a/test/docker/shadowsocksr.py b/test/docker/shadowsocksr.py index 0580093..90eff5f 100644 --- a/test/docker/shadowsocksr.py +++ b/test/docker/shadowsocksr.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + method_list = [ "aes-128-cfb", "aes-192-cfb", diff --git a/test/docker/sip003.py b/test/docker/sip003.py index 32a974e..7143c81 100644 --- a/test/docker/sip003.py +++ b/test/docker/sip003.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- coding:utf-8 -*- testHost = "dns.343.re" testCert = "/etc/ssl/certs/dns.343.re/certificate.crt"