ソースを参照

add: 重新添加netc泄漏测试脚本

Wendal Chen 5 年 前
コミット
74df373cc2
1 ファイル変更29 行追加29 行削除
  1. 29 29
      script/test/3.netc_leak_connect/main.lua

+ 29 - 29
script/test/3.netc_leak_connect/main.lua

@@ -1,34 +1,34 @@
 
-wlan.setMode("wlan0", 1)
-wlan.connect("uiot", "12345678")
+local sys = require "sys"
 
-local count = 0
-local netc_a, netc_b, netc_c, netc_d
-while count < 10000 do
-    if wlan.ready() == 1 then
-        -- 新建4个连接对象, 但不连接
-        netc_a = socket.tcp()
-        netc_b = socket.tcp()
-        netc_c = socket.tcp()
-        netc_d = socket.tcp()
-
-        --netc_a:host("site0.cn")
-        --netc_b:host("www.baidu.com")
-        --netc_c:host("nutz.cn")
-        --netc_d:host("qq.com")
-
-        netc_a:on("close", function() print(netc_a) end)
-        netc_b:on("close", function() print(netc_b) end)
-        netc_c:on("close", function() print(netc_c) end)
-        netc_d:on("close", function() print(netc_d) end)
+-- 如果是wifi,那就连一下wifi咯
+if wlan ~= nil then
+    wlan.connect("uiotabc", "12345678")
+end
 
-        netc_a:clean()
-        netc_b:clean()
-        netc_c:clean()
-        netc_d:clean()
+local tcount = 0        -- 当前测试完成数
+local testcount = 10000 -- 总测试次数
+sys.taskInit(function()
+    -- 做个大的循环
+    while tcount < testcount do
+        while not socket.isReady() then sys.waitUntil("NET_READY", 1000) end
+        local netc = socket.tcp()
+        netc:host("wwww.baidu.com")
+        netc:port(80)
+        netc:on("connect", function(id, re)
+            if re == 0 then
+                netc:send("GET / HTTP/1.0\r\n\r\n")
+            end
+        end)
+        netc:on("recv", function(id, data)
+            log.info("netc", "data recv", data)
+        end)
+        if netc:start() == 0 then
+            while netc:closed() == 0 then sys.waitUntil("NETC_END_" .. s:id(), 1000) end
+        end
+        netc:close()
+        sys.wait(1000) -- 等待1秒后继续测试
     end
-    timer.mdelay(100)
-    collectgarbage()
-    count = count + 1
-end
+end)
 
+sys.run()