Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2262736lqb; Mon, 27 May 2024 13:31:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWF4zAWso3eVPSxIGuuBtM/LcOpK0HIWS78cABhbpvktUl01V3ugz2c5TY3QSHjAJhtX8szIhjD3h9TLc/rkur3t+fy3zxm87mGdNL9yg== X-Google-Smtp-Source: AGHT+IGXC33ss8l2nRyPQJQjz+1Qm3nMrLZMaNj4m8yUTKpVvge2Yqx+XoJe/sGq+JZ5i5BKV81D X-Received: by 2002:a25:e0cd:0:b0:deb:bd1e:8f70 with SMTP id 3f1490d57ef6-df7721ce17amr13223195276.39.1716841874543; Mon, 27 May 2024 13:31:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716841874; cv=pass; d=google.com; s=arc-20160816; b=g42TDq2Dnqbvg2EcWB+zUbdB8TlUK+udam67ytk9RSn45DZ7tIMjV9CTQqzWHKc1xw NIgEFm4bN9tFAAEEiivAiqpRNp9Cqu42Bqg7e1+A51vV2MwPEJZYJK0r3vNVsg4i+5/i 3Mre4LO+lTnkEhUXqNcMx2G3IWcxVkiDJbNIyqObRBbymxURTmnufMllmsHpaPn/JjaJ lNOCsqoiSYQUQTRyfODuSZQ1Hl9w7171jHcqzahP8+4ddF2roIk5cpDSyPLn0DhZGpvx e77R5YusUNHW3bvdVBRANYtrPrHoDyDA+37KTadWXqNYS9kSADjViSEHljz1uT8xw2/W MVFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iVBlz0vl7yDyH9ZJUwo7OCKU71+Ygf2UNq0ZwoLT7g0=; fh=ODLc56m1dqD3FQ4OdjJpODlf+ODmcTMk3B2K7/2ZHM4=; b=pmOt3kViX607/2i8yNB2TwVQkYYkbnHG4kHZYYW1AhixnqNXwq8e39fqxI2Ghslfyo le5gbkX5q/En3c9HngFVltTcAT6D0LfTZzEUYwdBdfDV92S49a+uy3sxzTSV009q3nNr pgBBT18Y1B+doB9t8rd8ktS50Drb6jNKyMM1bzkfOsdGskW+puSNO+30M3MXivSuq2oX I64FYLp96EvYRlQ/7E+sFIeVEo7V+mZk/fUdada3VmcpV8xlqV5pJ9bwJ4ptxH4BoY0F VAsPd98xHTqX2WJOInhxwWZINQnvfO/CulnyjxxoeluQOl4LiPP8InCBHwACfj/8O2TY WAnw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CCWzREyg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-191393-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191393-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd3d71csi940852485a.500.2024.05.27.13.31.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 13:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191393-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CCWzREyg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-191393-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191393-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 498791C21296 for ; Mon, 27 May 2024 20:31:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4347116727E; Mon, 27 May 2024 20:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CCWzREyg" Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EDBA1667FC for ; Mon, 27 May 2024 20:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716841828; cv=none; b=FaF4cbKqnRVo/E4CsdrC5Fq8smFJVweoCqXKuk9J3x5ZDfvOQSZDvkO7VzL7b1AL3Vbv12rRgE2GLgnsbThVu3N4++Ktp4dcFvZY8xN7dERqsqaUfoDVg3cllBMgEeCZbfwNuyHNkG3F7Rw+KIJdtK8acVwY5VtnBWr7JvOTHEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716841828; c=relaxed/simple; bh=RKjvan0E7Im/7BRlGrzyeoNxj37ylBgB9GBoKbO6QUk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HwDxP3kM1xrJot68o/Bo+C7SpyT0J8ixvHfs+LEZLbpfEYSFAgkd3IsKWukT3Q0WjOnO0Mh/FQfPLyAjWH7Rv3FChuIU2NPjgbXhaJLx+OveUprd9J3YurvXNsfqItrWA9RFSHBF+yp4KyazlcxzcAkl7QljhKZ4Ic0kpTsONGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CCWzREyg; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-667fbbbf36dso9917a12.1 for ; Mon, 27 May 2024 13:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716841826; x=1717446626; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iVBlz0vl7yDyH9ZJUwo7OCKU71+Ygf2UNq0ZwoLT7g0=; b=CCWzREygNaU3QvnCMwO2kuJDGDFpPrXlDCvIrIThcnAoUL6CJmzUsz23ogv8sVPSR+ wRA5cFuDLQwO6XV4BkSU2KoFT31oueW+PbkiuXTzLj0DkbIUGoEg+VilA0pQbNnRlB5y m6AZx3hDttSkHeyzoN5fVD9kmclsikFlYyILvb7aab4xThEfUx6w/qUBGcg4Ff9OgMaW OKuW7uTm2Y3uEEnwqM5YkvrdphtR/iHmEuTIt83+E20fCdUdhrBFuoyTl0uH7nwrnFN0 YQl8fXwsUwRzlVEsPxpglhGShKcOqDl03qebrvUdrvCEncBKBJa7SOoXo2xE8fuJtjU/ 05Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716841826; x=1717446626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iVBlz0vl7yDyH9ZJUwo7OCKU71+Ygf2UNq0ZwoLT7g0=; b=cj483LK5q5SFpI/yO5+fAJVamVRTEMKpTiep/4KKtSXXgmCkOvxcX0qfHxzqpMosyb MJj4A9JbsW2+l0YhWUtKdxSUSkP8aqWC2ntAQIHVXgMoVGjKkIz+UJZ4CAlx98YsQAgS Rqjo90xuJjQzoqRo7CEg/oce6YhcMmKKMoSc0i65dRP1ZRWijY3kqHll7n5s1hZotAQw Q5R5Mivfdajk0Eu4yT8M5EHPfjEMozDV4xlegBBCEjqUGbHBIjEK3sIUfAXQfaVR2JEk iK4u+I85cfhn5MSrAx6m8Y1rdgRaWp+pVzaGxecE6XE5Ju3Y+V8FjLtdpJZhFmHUfJoc iEtw== X-Forwarded-Encrypted: i=1; AJvYcCUxs8uD3m2RwCO0YohMs6JbmaiYMQltTvlvtkB+XLG8qATSFZ6rJgAFlAkSzrrgoOQ7/AMvn8u4GVDn883SWF46CPoRkJHOqs6SKnpE X-Gm-Message-State: AOJu0Yy7ApLisYcgSAKaOoUAiwNlfsFGvgqre2zu4jHqMjLWJRJIp/5G vDvAsLeSIQrxt7wjIsrFTqZRCbvvG+FCAHI29tYtNlV4N+lmGV40 X-Received: by 2002:a05:6a20:9489:b0:1af:a4a5:a26a with SMTP id adf61e73a8af0-1b212cc65e8mr9715951637.1.1716841826471; Mon, 27 May 2024 13:30:26 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6822092a678sm5324279a12.11.2024.05.27.13.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 13:30:25 -0700 (PDT) From: Kuan-Wei Chiu To: akpm@linux-foundation.org Cc: jserv@ccns.ncku.edu.tw, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH 4/4] lib/test_sort: Add a testcase to ensure code coverage Date: Tue, 28 May 2024 04:30:11 +0800 Message-Id: <20240527203011.1644280-5-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527203011.1644280-1-visitorckw@gmail.com> References: <20240527203011.1644280-1-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The addition of an if statement in lib/sort to handle the final unsorted 2 or 3 elements is not covered by existing test cases, leading to incomplete test coverage. To ensure comprehensive testing and maintain 100% code coverage, add a new testcase for scenarios where the if statement is triggered. Since the if statement is only triggered when the array length is odd and the first element is greater than the second element, a testcase is created using an array length of TEST_LEN - 1 and a suitable random seed to maintain full code coverage. Signed-off-by: Kuan-Wei Chiu --- lib/test_sort.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/test_sort.c b/lib/test_sort.c index be02e3a098cf..da4495125097 100644 --- a/lib/test_sort.c +++ b/lib/test_sort.c @@ -29,7 +29,19 @@ static void test_sort(struct kunit *test) sort(a, TEST_LEN, sizeof(*a), cmpint, NULL); - for (i = 0; i < TEST_LEN-1; i++) + for (i = 0; i < TEST_LEN - 1; i++) + KUNIT_ASSERT_LE(test, a[i], a[i + 1]); + + r = 48; + + for (i = 0; i < TEST_LEN - 1; i++) { + r = (r * 725861) % 6599; + a[i] = r; + } + + sort(a, TEST_LEN - 1, sizeof(*a), cmpint, NULL); + + for (i = 0; i < TEST_LEN - 2; i++) KUNIT_ASSERT_LE(test, a[i], a[i + 1]); } -- 2.34.1