Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp31030pxj; Wed, 16 Jun 2021 19:25:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdzI9yFXt6x4xOA9kpF/w2hVx1zNNFOvLSKIchVDPqTfFMyXjuPpoFP0DLTi/VW2foQtg9 X-Received: by 2002:a17:907:9fd:: with SMTP id ce29mr2515851ejc.396.1623896723670; Wed, 16 Jun 2021 19:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623896723; cv=none; d=google.com; s=arc-20160816; b=aacc2MIvb39HsS+RkmK2QABcYILkzPbiBHixJUxXYFelxjE93kDOLMp+32JVUWS855 NjgXasnovzscnQIQ/6xHDOH0blrAosDkab7A4ES9U4NDbPpRet8SMSv1DApXh3/I57dg JK3pFGEMu9GnF5JHgpAbZ2f1uLGOTNybxGmnuD42FQnRufjKNZCyyLe4YpYze0042Uo0 PKFmrSpy0H5AFySfSvgf551Oo81yizXsofoRxGf3k4l3eeouT8u6dCXFGgRdeJ3wW8ZT 0VdbyiOIzfGfZ1wy4kqU44z6niNVa+SC4MK+4DC+Qs6XWi443eVWYgoQBsH5qFvA1N/C xBCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NxTx9dcN8kshXBEYUvRxmk5CMBPREQ9LTGjLkVS+6m8=; b=IzkS+POkMoXCDttsZI0s2jRtAhAHoS3YDqOAFq3uaec+8NBLM2TCpPkUFZIsKdMQ6K odnQ3ZBKgiQJMgrum4RmLOjd/uxNJ6TJX7kb+O6NbEPi9X+nO9LHBuQ4blocxr+Yw+hg 90EVFARqnpMj+QngT9Evu1QnV618O9I09QqF7uuieb5n64jGhhjT2H2KjzodDnjBErl6 +NrvXDrrKx+xHqllszhgOM5aICdGISjmOJ6JPSeLhSEweC3h6D9A1K+YFtFFz01Zg78X ZbIZ7kn/v1fU5Eoq1okP8yQRn7sh4vbJgamwZQ8qYDRdp9C7wZWx2d9TO8YpVzkrmVHL 2sAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XSRKjVo8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si3799443eje.327.2021.06.16.19.25.01; Wed, 16 Jun 2021 19:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XSRKjVo8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbhFPVBg (ORCPT + 99 others); Wed, 16 Jun 2021 17:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbhFPVBf (ORCPT ); Wed, 16 Jun 2021 17:01:35 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E857C06175F for ; Wed, 16 Jun 2021 13:59:29 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id t9so3047923pgn.4 for ; Wed, 16 Jun 2021 13:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NxTx9dcN8kshXBEYUvRxmk5CMBPREQ9LTGjLkVS+6m8=; b=XSRKjVo8Azlog98paZINOAdn6bOlODpJpRI653o306QtfNPOx4l2/WQSfD5y9wR2BH SQHhuwknCv8x8CcTKk4CDzgYlKoguOL9XSk67LHxzMHxBHgSdolWSYCIPGSeHX2ZhncL 8sWtQHwjHJc4Idj7Yktb8SbVHCB3LtBMDvHTLPAFJQOxTUqH3If1mEDCBSIxKtyf4TWx et6uc8yGbCb7939Xa/7yup5CBc5cPmehbEmh+jH1HOWp7LYBIdAgyPm3I4s118lnbVVF mK/rmKWoV1GzT1l49/B9/rAve3E658CnS0Q9c1sbilmZkKC70QxWUwlcIaotqBtlfaLw j51w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NxTx9dcN8kshXBEYUvRxmk5CMBPREQ9LTGjLkVS+6m8=; b=lwEFJicU+NXN2s+M7r5rhnwn349E+dhfv3zFM46j937Ox2hxdSXqfz1aCUCqeRCu6M a5MRwTkhxyBf+X1HmL1n/1MI17pcN7e+8OkcI4q0vWdMni/coZMjHDBs1aymekV4Q0IX fVof59nN5QqWwyJoClNoJXkCFfDAhFtAk0aoz9ikLl7KOKdrYiCQZIfv7uqX2xxYhTCO E0Dz4zSpnnhexTgTngWp7djDw4kvK/hf2sxdnUDI+V/6r0JmI2tkjT61uDuRUBDGcnKD dmO6rddO33uBAbwaR0RJG5HatQB/DX+MOrXrRKZyisnqcObwWqbbTUaVhreEFNsag8ge 2ztw== X-Gm-Message-State: AOAM532eGENJ/2GoE1faDR/l8LjdKUSJmZIupawTSjJprH/W5lyNr7RE EsqFlHp6PfVkgnbHVYivy6E+89TACYP+G7Xs42kkdg== X-Received: by 2002:a63:d0d:: with SMTP id c13mr1570973pgl.384.1623877168348; Wed, 16 Jun 2021 13:59:28 -0700 (PDT) MIME-Version: 1.0 References: <20210526082217.333194-1-dlatypov@google.com> In-Reply-To: <20210526082217.333194-1-dlatypov@google.com> From: Brendan Higgins Date: Wed, 16 Jun 2021 13:59:17 -0700 Message-ID: Subject: Re: [PATCH v2] kunit: tool: internal refactor of parser input handling To: Daniel Latypov Cc: David Gow , Linux Kernel Mailing List , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 26, 2021 at 1:22 AM Daniel Latypov wrote: > > Note: this does not change the parser behavior at all (except for making > one error message more useful). This is just an internal refactor. > > The TAP output parser currently operates over a List[str]. > This works, but we only ever need to be able to "peek" at the current > line and the ability to "pop" it off. > > Also, using a List means we need to wait for all the output before we > can start parsing. While this is not an issue for most tests which are > really lightweight, we do have some longer (~5 minutes) tests. > > This patch introduces an LineStream wrapper class that > * Exposes a peek()/pop() interface instead of manipulating an array > * this allows us to more easily add debugging code [1] > * Can consume an input from a generator > * we can now parse results as tests are running (the parser code > currently doesn't print until the end, so no impact yet). > * Tracks the current line number to print better error messages > * Would allow us to add additional features more easily, e.g. storing > N previous lines so we can print out invalid lines in context, etc. > > [1] The parsing logic is currently quite fragile. > E.g. it'll often say the kernel "CRASHED" if there's something slightly > wrong with the output format. When debugging a test that had some memory > corruption issues, it resulted in very misleading errors from the parser. > > Now we could easily add this to trace all the lines consumed and why > +import inspect > ... > def pop(self) -> str: > n = self._next > + print(f'popping {n[0]}: {n[1].ljust(40, " ")}| caller={inspect.stack()[1].function}') > > Example output: > popping 77: TAP version 14 | caller=parse_tap_header > popping 78: 1..1 | caller=parse_test_plan > popping 79: # Subtest: kunit_executor_test | caller=parse_subtest_header > popping 80: 1..2 | caller=parse_subtest_plan > popping 81: ok 1 - parse_filter_test | caller=parse_ok_not_ok_test_case > popping 82: ok 2 - filter_subsuite_test | caller=parse_ok_not_ok_test_case > popping 83: ok 1 - kunit_executor_test | caller=parse_ok_not_ok_test_suite > > If we introduce an invalid line, we can see the parser go down the wrong path: > popping 77: TAP version 14 | caller=parse_tap_header > popping 78: 1..1 | caller=parse_test_plan > popping 79: # Subtest: kunit_executor_test | caller=parse_subtest_header > popping 80: 1..2 | caller=parse_subtest_plan > popping 81: 1..2 # this is invalid! | caller=parse_ok_not_ok_test_case > popping 82: ok 1 - parse_filter_test | caller=parse_ok_not_ok_test_case > popping 83: ok 2 - filter_subsuite_test | caller=parse_ok_not_ok_test_case > popping 84: ok 1 - kunit_executor_test | caller=parse_ok_not_ok_test_case > [ERROR] ran out of lines before end token > > Signed-off-by: Daniel Latypov > Reviewed-by: David Gow Acked-by: Brendan Higgins