Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3481382pxj; Mon, 24 May 2021 07:43:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymP+b57h/kolAeSWG+DtDn78W7AZx+Knt9b91k4sJGCtWgOTAKTFGZNfLfyLAoy5Ofm/QE X-Received: by 2002:a17:906:b104:: with SMTP id u4mr23418315ejy.211.1621867420421; Mon, 24 May 2021 07:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621867420; cv=none; d=google.com; s=arc-20160816; b=yFkMhWjhwH8H1RmMVHKkohV0jw04+8R6V35X6O3EtMnwqhSQDzx+0acP8pKZcFbU1w 6SmhlplhujS66XH8yvFA7DrFMWm2DDm7daA+VBz8iGTdNX5ByNFfc0ZifgpECJ/IPQ5a jyqu1gmapv6W4fYSrSpQlv3+IcHb9Hd82vPFwh10FMgECNkr3pXYuhvLg+4pKuz7OHvW P0qV6OJ5vIa9OfRPR3OlJBSR2KwmTjrO9RhB9rlNClQgeYCKk4HZvpBeAKIsqXjrknYp pwvcFh4u1CuerVNz12thqnh5i/ttCCD0EfhlbbMyeKCgLXTNUQsidfFyzuGEf2zhbDau JTpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=oyCraAAtXrZ48Fn8CBGwDhVCjV34QqFZgAv/Uzo73YY=; b=u8xYfgOGcGn0QyxEjcncDnRdZomCllvddkEhY/9uvhl+YDlQL/tm/R5NyiDmxd6Bm7 YEDY1BczMGu0IIyyBZR2B2nIJ9wj++mtmyRC+PGNNrpdExJMM0Xcgw8sS575d3lpMmQH WmutnKZBWswensDEOYm5xqEGuHVI2l5UZnPGdeRxm8X5LVyi6wRtWpgwddxt0vER5KsY VCe7rgF1bPiSQKRylVWbBx6lNEaCrXQINKqV047kA/YCL4E1eReyR/73UMbh61b/xCB4 YIPx8KzmAOTzGONw03pJEu0X8SGHGUTOtwF68e0fXauQ6ms2jNV3uY+Q8ysfvy/cmFQO p3CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=rAkeVdqs; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd21si12485422edb.261.2021.05.24.07.43.12; Mon, 24 May 2021 07:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@suse.cz header.s=susede2_rsa header.b=rAkeVdqs; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233026AbhEXOo1 (ORCPT + 99 others); Mon, 24 May 2021 10:44:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:40622 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233022AbhEXOo0 (ORCPT ); Mon, 24 May 2021 10:44:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621867377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oyCraAAtXrZ48Fn8CBGwDhVCjV34QqFZgAv/Uzo73YY=; b=rAkeVdqswKxyWqd7oM7OEksPPKu5zirDkANuUfGEO0oHGvpOHr/ASLuDORHM33xnBB9j/+ j6QfVfrkkUoOndrsxnO/rrRHjFH+cqxNZgaAJVHc6dFhqty2Jl0VC3LeOaOevvh9EcjD7f clweAIaGcWn+Zih0708RCYSZ/IZQlus= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621867377; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oyCraAAtXrZ48Fn8CBGwDhVCjV34QqFZgAv/Uzo73YY=; b=C5fP2dT01D287XZGS3Xkd8MlV7/hbsWxDWhkaTopPGGSnYt8KKTEZsyksmLwS2Ke0w9JLl Bk7rIV2m/lPwSqAA== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B625BADE7; Mon, 24 May 2021 14:42:57 +0000 (UTC) From: Petr Vorel To: linux-nfs@vger.kernel.org Cc: Petr Vorel , "J . Bruce Fields" , "Yong Sun (Sero)" Subject: [PATCH pynfs 2/3] server: Allow to print JSON format Date: Mon, 24 May 2021 16:42:50 +0200 Message-Id: <20210524144251.30196-2-pvorel@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524144251.30196-1-pvorel@suse.cz> References: <20210524144251.30196-1-pvorel@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Petr Vorel --- nfs4.0/testserver.py | 7 ++++++- nfs4.1/testmod.py | 40 +++++++++++++++++++++++++++++++++++++++- nfs4.1/testserver.py | 6 +++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/nfs4.0/testserver.py b/nfs4.0/testserver.py index 0ef010a..f2c4156 100755 --- a/nfs4.0/testserver.py +++ b/nfs4.0/testserver.py @@ -85,6 +85,8 @@ def scan_options(p): help="Skip final cleanup of test directory") p.add_option("--outfile", "--out", default=None, metavar="FILE", help="Store test results in FILE [%default]") + p.add_option("--jsonout", "--json", default=None, metavar="FILE", + help="Store test results in JSON format [%default]") p.add_option("--xmlout", "--xml", default=None, metavar="FILE", help="Store test results in xml format [%default]") p.add_option("--debug_fail", action="store_true", default=False, @@ -378,8 +380,11 @@ def main(): if fail: print("\nWARNING: could not clean testdir due to:\n%s\n" % err) - if opt.xmlout is not None: + if opt.jsonout is not None: + testmod.json_printresults(tests, opt.jsonout) + elif opt.xmlout is not None: testmod.xml_printresults(tests, opt.xmlout) + if nfail < 0: sys.exit(3) if nfail > 0: diff --git a/nfs4.1/testmod.py b/nfs4.1/testmod.py index e368853..4b4ed24 100644 --- a/nfs4.1/testmod.py +++ b/nfs4.1/testmod.py @@ -13,6 +13,7 @@ import re import sys import time from traceback import format_exception, print_exc +import json import xml.dom.minidom import datetime @@ -467,6 +468,43 @@ def printresults(tests, opts, file=None): (count[SKIP], count[FAIL], count[WARN], count[PASS]), file=file) return count[FAIL] +def json_printresults(tests, file_name, suite='all'): + with open(file_name, 'w') as fd: + failures = 0 + skipped = 0 + total_time = 0 + data = {} + data["tests"] = len(tests) + data["errors"] = 0 + data["timestamp"] = str(datetime.datetime.now()) + data["name"] = suite + data["testcase"] = [] + for t in tests: + test = { + "name": t.name, + "classname": t.suite, + "time": str(t.time_taken), + } + + total_time += t.time_taken + if t.result == TEST_FAIL: + failures += 1 + test["failure"] = { + "message" : t.result.msg, + "err" : ''.join(t.result.tb) + } + elif t.result == TEST_OMIT: + skipped += 1 + test["skipped"] = 1 + + data["testcase"].append(test) + + data["failures"] = failures + data["skipped"] = skipped + data["time"] = total_time + + fd.write(json.dumps(data, indent=4, sort_keys=True)) + def xml_printresults(tests, file_name, suite='all'): with open(file_name, 'w') as fd: failures = 0 @@ -484,7 +522,7 @@ def xml_printresults(tests, file_name, suite='all'): testsuite.appendChild(testcase) testcase.setAttribute("name", t.name) testcase.setAttribute("classname", t.suite) - testcase.setAttribute("time", str(t.time_taken)) + testcase.setAttribute("time", t.time_taken) total_time += t.time_taken if t.result == TEST_FAIL: diff --git a/nfs4.1/testserver.py b/nfs4.1/testserver.py index d3c44c7..085f007 100755 --- a/nfs4.1/testserver.py +++ b/nfs4.1/testserver.py @@ -68,6 +68,8 @@ def scan_options(p): help="Skip final cleanup of test directory") p.add_option("--outfile", "--out", default=None, metavar="FILE", help="Store test results in FILE [%default]") + p.add_option("--jsonout", "--json", default=None, metavar="FILE", + help="Store test results in JSON format [%default]") p.add_option("--xmlout", "--xml", default=None, metavar="FILE", help="Store test results in xml format [%default]") p.add_option("--debug_fail", action="store_true", default=False, @@ -363,7 +365,9 @@ def main(): if fail: print("\nWARNING: could not clean testdir due to:\n%s\n" % err) - if opt.xmlout is not None: + if opt.jsonout is not None: + testmod.json_printresults(tests, opt.jsonout) + elif opt.xmlout is not None: testmod.xml_printresults(tests, opt.xmlout) if __name__ == "__main__": -- 2.31.1