From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EAA42455FE; Thu, 11 Jul 2024 17:31:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7BF742E63; Thu, 11 Jul 2024 17:31:13 +0200 (CEST) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id B82D1402D6 for ; Thu, 11 Jul 2024 17:31:12 +0200 (CEST) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fbcf71d543so7352325ad.1 for ; Thu, 11 Jul 2024 08:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1720711872; x=1721316672; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OuN/Q7F5Mol+yW8XbpwbrwLkt0BLE1wH/ufnMHfuCuk=; b=gue6TdbBX8KxiyNbb5gd7pSV5wWidDBtbfIukKMkCaUcUNDoO/QbCOIjsEYT1S/c7L D8Oyh5LGuMRpJCt13vcNEozqe8WQFm39SC8GlrLKY55ZPPtMF63Mhppg/6hwl2pVhzWC +pwbKzLNpH99gKmD5F3q3w7FztH/JOJI3cbO0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720711872; x=1721316672; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OuN/Q7F5Mol+yW8XbpwbrwLkt0BLE1wH/ufnMHfuCuk=; b=gRpfZRY5TUHC2pWWAhAwZMQYSxA04nox37Unf1sFvSglJIAc+UhtYwM57rCkC7V8Iq 8/lrIa2ForuRFLg5OT9kmumCNVmZ8B+uFBu+4zKJ1m+AgH6M9oIXEt3G1+gDIkdpktdq kWt39+EHxZoUCk2ZiJ0jBR4mm85h0uXpTBYq7NtjrF5w5nHVWIAPe103TJR6/y9FB6qy L+fyUJy8rGapNvHnaD8KZJlM772RSJNaf6tXzjm0K988sxWxFUQX2MmwBUCe0UXYUWTT TZBQocokZGGYi4AVZrXUBzKLKLgG/gM+/gQdeM+K07+fMUuD2rHhV7n7R7ekgyuJJamm 11BA== X-Forwarded-Encrypted: i=1; AJvYcCWjqdKEC167yE3onTiWi3NzrheYAWRqgJop9PWD0vI0Gmwy6WA/HhooQcLaXd8jCNhCWO7V6Z74L7gf1yU= X-Gm-Message-State: AOJu0Yxtq2P2QIhavWiuSQHBlYLWC3yHAsyMKfo30/OLN3FWoE9K//cQ ZK4ACFU6av2Mmm8WcLOfc/iOH6cpmBjf/rz+91ApfpOG1RX/BHkZPpegLJBEMyjv+ANneq9603Z KAh/ZOwfYC3riHz1C1Uz4R6MiHHXfvdW6kLhl1A== X-Google-Smtp-Source: AGHT+IHZOW1nzcsbD1ck5msrHrIQgHnnSpc2pjIwnMgPQsBaqa8WE/qZvDK+IWC7M1E0CJPtTjVs+INXkCl3eT92uR4= X-Received: by 2002:a17:903:32c5:b0:1fb:34ef:4467 with SMTP id d9443c01a7336-1fbb6d893a3mr70210795ad.43.1720711871690; Thu, 11 Jul 2024 08:31:11 -0700 (PDT) MIME-Version: 1.0 References: <20240709163145.110030-1-jspewock@iol.unh.edu> <20240709163145.110030-2-jspewock@iol.unh.edu> <6a2b6fd6-e18b-4844-9b5f-b40fdf81c76d@pantheon.tech> In-Reply-To: <6a2b6fd6-e18b-4844-9b5f-b40fdf81c76d@pantheon.tech> From: Jeremy Spewock Date: Thu, 11 Jul 2024 11:31:00 -0400 Message-ID: Subject: Re: [PATCH v1 1/2] dts: add context manager for interactive shells To: =?UTF-8?Q?Juraj_Linke=C5=A1?= Cc: yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com, thomas@monjalon.net, paul.szczepanek@arm.com, probb@iol.unh.edu, npratte@iol.unh.edu, Luca.Vizzarro@arm.com, wathsala.vithanage@arm.com, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, Jul 11, 2024 at 10:35=E2=80=AFAM Juraj Linke=C5=A1 wrote: > > > > On 9. 7. 2024 18:31, jspewock@iol.unh.edu wrote: > > From: Jeremy Spewock > > > > Interactive shells are managed in a way currently where they are closed > > and cleaned up at the time of garbage collection. Due to there being no > > guarantee of when this garbage collection happens in Python, there is n= o > > way to consistently know when an application will be closed without > > manually closing the application yourself when you are done with it. > > This doesn't cause a problem in cases where you can start another > > instance of the same application multiple times on a server, but this > > isn't the case for primary applications in DPDK. The introduction of > > primary applications, such as testpmd, adds a need for knowing previous > > instances of the application have been stopped and cleaned up before > > starting a new one, which the garbage collector does not provide. > > > > To solve this problem, a new class is added which acts as a base class > > for interactive shells that enforces that instances of the > > application be managed using a context manager. Using a context manager > > guarantees that once you leave the scope of the block where the > > application is being used for any reason, the application will be close= d > > immediately. This avoids the possibility of the shell not being closed > > due to an exception being raised or user error. The interactive shell > > class then becomes shells that can be started/stopped manually or at th= e > > time of garbage collection rather than through a context manager. > > > > Signed-off-by: Jeremy Spewock > > Reviewed-by: Juraj Linke=C5=A1 > > Reviewed-by: Patrick Robb > > Reviewed-by: Luca Vizzarro > > --- > > Just one minor inconsequential point below. My tag is still valid. > > > diff --git a/dts/tests/TestSuite_smoke_tests.py b/dts/tests/TestSuite_s= moke_tests.py > > index eca27acfd8..377bff129d 100644 > > --- a/dts/tests/TestSuite_smoke_tests.py > > +++ b/dts/tests/TestSuite_smoke_tests.py > > @@ -100,7 +100,8 @@ def test_devices_listed_in_testpmd(self) -> None: > > List all devices found in testpmd and verify the configur= ed devices are among them. > > """ > > testpmd_driver =3D TestPmdShell(self.sut_node) > > - dev_list =3D [str(x) for x in testpmd_driver.get_devices()] > > + with testpmd_driver as testpmd: > > The usual way to use context managers in Python is without the intent of > using the object after it leaves the context: > > with TestPmdShell(self.sut_node) as testpmd: > > That said, the way you did it in the scatter test case seems fine > because it looks more readable. Maybe we can just change it here, but > it's a minor point and doesn't really matter. > This is a good point. Originally I also did it in two separate lines because it used to have to be a call to a sut_node method and was just long and convoluted, but I think now that you instantiate the class directly doing it this way makes more sense. I have no problem with updating both of them. Just as one thing to note however, this context manager is a little different by design. When writing it I actually made some minor tweaks specifically so that the same instance could be used multiple times. I figured this was something that we didn't really need to use and probably wouldn't use often, but could be useful in the future if you needed a shell that was identical ("identical" as in parameters-wise, of course the instances would be different) across test cases since all leaving the context does is close the shell. > > + dev_list =3D [str(x) for x in testpmd.get_devices()] > > for nic in self.nics_in_node: > > self.verify( > > nic.pci in dev_list,