From 31e5d47089d261f4731c8f56ab5ece0d8fb1be36 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 17 Sep 2024 09:14:37 +0200 Subject: [PATCH] chore(test/libsinsp_e2e,ci): port libsinsp_e2e tests to use python3. Signed-off-by: Federico Di Pierro --- .github/workflows/e2e_ci.yml | 2 +- .../resources/unix_client_server.py | 17 +++++++---------- test/libsinsp_e2e/unix_client_server.cpp | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/e2e_ci.yml b/.github/workflows/e2e_ci.yml index 95f7fbcfb2..48fcfc4ad2 100644 --- a/.github/workflows/e2e_ci.yml +++ b/.github/workflows/e2e_ci.yml @@ -147,7 +147,7 @@ jobs: - name: Install deps run: | - sudo apt install -y --no-install-recommends clang gcc llvm build-essential cmake python2 + sudo apt install -y --no-install-recommends clang gcc llvm build-essential cmake python3 quota - name: Install kernel headers (actuated) uses: self-actuated/get-kernel-sources@201eed7d915ac0a6021fb402cde5be7a6b945b59 diff --git a/test/libsinsp_e2e/resources/unix_client_server.py b/test/libsinsp_e2e/resources/unix_client_server.py index f183eaac65..5f0b17cecc 100644 --- a/test/libsinsp_e2e/resources/unix_client_server.py +++ b/test/libsinsp_e2e/resources/unix_client_server.py @@ -1,22 +1,21 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # coding: utf-8 -*- import socket import os, os.path -import time import sys PAYLOAD = "0123456789QWERTYUIOPASDFGHJKLZXCVBNM" NAME = "/tmp/python_unix_sockets_example" - +STARTED = "STARTED" + if sys.argv[1] == 'server': if os.path.exists(NAME): os.remove(NAME) server = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) server.bind(NAME) - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) - print "STARTED" + print(STARTED) server.listen(5) connect, address = server.accept() @@ -27,17 +26,15 @@ os.remove(NAME) else: - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) - if os.path.exists(NAME): client = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) client.connect(NAME) - print "STARTED" + print(STARTED) - client.send(PAYLOAD) + client.send(PAYLOAD.encode()) resp = client.recv(1024) client.close() else: - print >> sys.stderr, "Couldn't Connect!" + print("Couldn't Connect!", file=sys.stderr) diff --git a/test/libsinsp_e2e/unix_client_server.cpp b/test/libsinsp_e2e/unix_client_server.cpp index 6d4d38004e..a668cb3e8a 100644 --- a/test/libsinsp_e2e/unix_client_server.cpp +++ b/test/libsinsp_e2e/unix_client_server.cpp @@ -90,7 +90,7 @@ TEST_F(sys_call_test, unix_client_server) { event_filter_t filter = [&](sinsp_evt* evt) { sinsp_threadinfo* ti = evt->get_thread_info(false); if(ti) { - if(ti->get_comm() == "python2" && ti->m_args.size() >= 1) { + if(ti->get_comm() == "python3" && ti->m_args.size() >= 1) { return ends_with(ti->m_args[0], "unix_client_server.py") || ends_with(ti->m_args[0], "unix_client_server.py"); } @@ -103,12 +103,12 @@ TEST_F(sys_call_test, unix_client_server) { // INITIALIZATION // run_callback_t test = [](concurrent_object_handle inspector) { - subprocess server("python2", + subprocess server("python3", {LIBSINSP_TEST_RESOURCES_PATH "/unix_client_server.py", "server"}); server.wait_for_start(); - subprocess client("python2", + subprocess client("python3", {LIBSINSP_TEST_RESOURCES_PATH "/unix_client_server.py", "client"}); server.wait(); client.wait();