Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 11/11] support/testing/tests: add test for file overwrite detection
Date: Sat, 25 Jul 2020 14:05:23 +0200	[thread overview]
Message-ID: <20200725120523.GB19818@scaer> (raw)
In-Reply-To: <20200430095249.782597-12-thomas.petazzoni@bootlin.com>

Thomas, All,

On 2020-04-30 11:52 +0200, Thomas Petazzoni spake thusly:
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
[--SNIP--]
> diff --git a/support/testing/tests/core/test_file_overwrite.py b/support/testing/tests/core/test_file_overwrite.py
> new file mode 100644
> index 0000000000..526ed55e43
> --- /dev/null
> +++ b/support/testing/tests/core/test_file_overwrite.py
> @@ -0,0 +1,47 @@
> +import infra
> +import infra.basetest
> +import subprocess
> +
> +
> +class DetectTargetFileOverwriteTest(infra.basetest.BRConfigTest):
> +    config = \
> +        infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> +        infra.basetest.MINIMAL_CONFIG + \
> +        """
> +        BR2_PER_PACKAGE_DIRECTORIES=y
> +        BR2_PACKAGE_DETECT_OVERWRITE=y
> +        """
> +    br2_external = [infra.filepath("tests/core/br2-external/detect-overwrite")]
> +
> +    def test_run(self):
> +        with self.assertRaises(SystemError):
> +            self.b.build()
> +        logf_path = infra.log_file_path(self.b.builddir, "build",
> +                                        infra.basetest.BRConfigTest.logtofile)
> +        if logf_path:
> +            s = './etc/passwd: FAILED'
> +            logf = open(logf_path, "r")
> +            ret = subprocess.call(["grep", "-q", s], stdin=logf)
> +            self.assertEqual(ret, 0)

This does not need a subprocess, and can be done efficiently in python,
like suggested in my review of patch 10.

Note thatif the search pattern does not occur at the beginning of the
line, we can do:

    s = 'blabla'
    for open(log_path, "r") as f:
        lines = [l for l in f.readlines() if s in l]

Ditto for the other test, of course. ;-)

Regards,
Yann E. MORIN.

> +
> +class DetectHostFileOverwriteTest(infra.basetest.BRConfigTest):
> +    config = \
> +        infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> +        infra.basetest.MINIMAL_CONFIG + \
> +        """
> +        BR2_PER_PACKAGE_DIRECTORIES=y
> +        BR2_PACKAGE_HOST_DETECT_OVERWRITE=y
> +        """
> +    br2_external = [infra.filepath("tests/core/br2-external/detect-overwrite")]
> +
> +    def test_run(self):
> +        with self.assertRaises(SystemError):
> +            self.b.build()
> +        logf_path = infra.log_file_path(self.b.builddir, "build",
> +                                        infra.basetest.BRConfigTest.logtofile)
> +        if logf_path:
> +            s = './lib/pkgconfig/libpkgconf.pc: FAILED'
> +            logf = open(logf_path, "r")
> +            ret = subprocess.call(["grep", "-q", s], stdin=logf)
> +            self.assertEqual(ret, 0)


> -- 
> 2.25.4
> 

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  reply	other threads:[~2020-07-25 12:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30  9:52 [Buildroot] [PATCH 00/11] Overwritten file detection, improvements to file listing logic Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 01/11] package/pkg-generic.mk: use $(PKG)_NAME in step_pkg_size_after Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 02/11] package/pkg-generic.mk: drop useless $(1) argument in step_pkg_size_{before, after} Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 03/11] package/pkg-generic.mk: introduce final 'install' step Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 04/11] package/pkg-generic.mk: create directories upfront in the configure step Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 05/11] package/pkg-generic.mk: rework pkg_size logic with the "installed" step Thomas Petazzoni
2020-05-01 20:44   ` Yann E. MORIN
2020-05-02  9:52     ` Thomas Petazzoni
2020-04-30  9:52 ` [Buildroot] [PATCH 06/11] package/pkg-generic.mk: exclude the staging sub-directory Thomas Petazzoni
2020-05-01 20:57   ` Yann E. MORIN
2020-04-30  9:52 ` [Buildroot] [PATCH 07/11] package/pkg-generic.mk: move pkg_size_{before, after} and check_bin_arch functions Thomas Petazzoni
2020-05-01 21:01   ` Yann E. MORIN
2020-04-30  9:52 ` [Buildroot] [PATCH 08/11] package/pkg-generic.mk: detect files overwritten in TARGET_DIR and HOST_DIR Thomas Petazzoni
2020-05-01 21:23   ` Yann E. MORIN
2020-07-24 19:53     ` Yann E. MORIN
2020-07-25  5:58       ` Peter Korsgaard
2020-07-25  7:13         ` Yann E. MORIN
2020-07-25  8:12           ` Peter Korsgaard
2020-04-30  9:52 ` [Buildroot] [PATCH 09/11] support/testing/infra: add log_file_path() function Thomas Petazzoni
2020-07-24 20:11   ` Yann E. MORIN
2020-04-30  9:52 ` [Buildroot] [PATCH 10/11] support/testing/tests: add test for check_bin_arch Thomas Petazzoni
2020-07-25 11:59   ` Yann E. MORIN
2020-04-30  9:52 ` [Buildroot] [PATCH 11/11] support/testing/tests: add test for file overwrite detection Thomas Petazzoni
2020-07-25 12:05   ` Yann E. MORIN [this message]
2020-07-23 20:54 ` [Buildroot] [PATCH 00/11] Overwritten file detection, improvements to file listing logic Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200725120523.GB19818@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox