[Toybox] [PATCH] Fix truncate.test for macOS.

enh enh at google.com
Fri Jun 24 17:35:24 PDT 2022


On Thu, Jun 23, 2022 at 11:48 PM Rob Landley <rob at landley.net> wrote:

> On 6/22/22 20:02, enh wrote:
> > On Wed, Jun 22, 2022 at 1:52 PM Rob Landley <rob at landley.net
> > <mailto:rob at landley.net>> wrote:
>
> The problem with the mac tar test is even though it's easy enough to find
> what
> /etc/passwd calls UID 0:
>
> ROOT="$(sed -n '/[^:]*:[^:]*:0:/s/:.*//p' /etc/passwd)"
>
> That doesn't change the fact it'll be putting a different string into the
> tarball, with different sha1sums. Um. (I was using "root" as the one known
> constant account that didn't vary across distros. Possibly I need a way to
> tell
> it to use an alternate /etc/passwd file to lookup usernames. This is why
> I've
> been poking at mkroot, but making that work on a mac is just... ow.)
>

note that it's /etc/*group* that's weird, not *passwd*. uid 0 is root, but
group 0 is wheel. (i think that's true of all bsds?)

it actually looks like gid 0 is one of the few low gids that differs?

here's macos' first few gids:

nobody:*:-2:
nogroup:*:-1:
wheel:*:0:root
daemon:*:1:root
kmem:*:2:root
sys:*:3:root
tty:*:4:root

most of those are the same on linux.


> >     On 6/20/22 21:32, enh via Toybox wrote:
> >     > Specifically we were ending up with 2048 blocks allocated, and
> that --
> >     > not the stat(1) behavior -- was the reason why this test was
> failing
> >     > on macOS.
> >
> >     Yay, I got thunderbird sending email through gmail again! (The
> version upgrade
> >     changed the authentication type in the smtp server settings, but I
> could still
> >     set it BACK...)
> >
> >     I wanted a partially sparse file there, which truncate was
> preserving the
> >     contents of.
> >
> > i must be missing something ... why is it _partially_ sparse?
>
> Because truncate should be able to extend an existing file sparsely without
> damaging the existing contents, but I see that the existing test wasn't
> doing
> what I thought it was doing...
>
> So hang on, if we made a file completely sparse in 3 segments, how many
> blocks
> does MacOS think it's allocated? Can I dig this out of the macos test log
> on github?
>
> https://github.com/landley/toybox/runs/7008521598?check_suite_focus=true
>
> scripts/test.sh
> scripts/runtest.sh: line 223: syntax error near unexpected token `;'
> scripts/runtest.sh: line 223: `      R) LEN=0; B=1; ;&'
>
> It _starts_ with a syntax error, and THEN proceeds to run the tests. I
> don't
> understand what it's doing here?
>

(that's similar to what you see on Android with mksh at the moment ---
there's some error but apparently it's harmless because the tests run
anyway.)


> Scroll, scroll, scroll through the test results. VERBOSE=allnopass is
> probably
> your friend here...
>
> No it does not. And I don't have a mac to try this on. Hmmm...
>

happy to run commands if you send me them.


> >     There's %b and %B which is block size and size per block, and bash
> >     can do:
> >
> >       $ x=1+3; echo $((x))
> >       4
> >
> >     So what I should probably do is:
> >
> >     X=$(stat -c %B); [ $(($(stat -c %b freep)*X)) -le $((12345+X)) ]]
>
> Except toybox --help stat says "%b  Size/512" so the units SHOULD be 512.
> It's
> never NOT 512 in Linux, and I remember a certain amount of digging to
> confirm
> this at the time? Hmmm. (Is the "right fix" to get the macos build to
> behave
> like the linux build?)
>
> >     The problem is, you're not using bash or toysh for these tests,
> you're using a
> >     shell of unknown capabilities. Can the macos and android shells do
> that?
> >
> > macos _is_ bash, it's just 3.2.57 from 2007, for exactly the reason
> you'd assume.
>
> They swapped to zsh three years ago:
>
>
> https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features


oh, yeah, good point. my reaction to that was similar to your reaction to
dash. _i'll_ be using bash on macos until they remove it.


>
> That said I THINK all this $((math)) stuff I've been proposing is posix?
> So it
> should work...?
>

yeah, certainly your

x=1+3; echo $((x))

example works the same on both zsh and old bash (printing 4) on this mac.


> > android is mksh, which is available as a debian package; i often do
> "android"
> > shell testing that way for convenience :-)
> >
> > if you send me a patch i can test it for you ... but feel free to just
> commit
> > "the right thing" and we can work from there!
>
> I'm no longer convinced I know what the right thing is here. Possibly the
> "delete and recreate" workaround is best, but I have no idea WHY it
> works...
>
> I'm tempted to borrow my wife's mac for a bit, but I have no idea how to
> set up
> a development environment on a mac. The first google hit is
> https://sourabhbajaj.com/mac-setup/Xcode/ which looks... more elaborate
> than I
> want to do on a borrowed machine.
>

iirc it's a bit simpler than that (if you don't have some company policy
that says you can only install binaries from their servers) --- you just
run "make" and it pops up a window saying "you want to install all that
shit?" and you say "it's a unix system; i know this", bish bash bosh, job
done.

or, like i say, commit something that works on linux and i'll be your test
monkey.


> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20220624/e5f90bc4/attachment.htm>


More information about the Toybox mailing list