* [musl] [PATCH libc-test v3] functional: add mntent test
@ 2024-10-19 18:16 Alyssa Ross
2024-10-22 10:03 ` Szabolcs Nagy
0 siblings, 1 reply; 5+ messages in thread
From: Alyssa Ross @ 2024-10-19 18:16 UTC (permalink / raw)
To: musl
This only checks reading an fstab from an stream. I haven't written
tests for setmntent(), addmntent(), or hasmntnent().
test_getmntent exposes a bug in musl 1.2.3 where lines omitting the
final two fields, which are supposed to be optional according to
fstab(5), are not accepted. It also exposes a current bug, where if
the numeric fields are omitted, the last field seen will have a
newline appended to its value. The tests all pass on Glibc.
---
v3: updated description for current musl
v2: https://inbox.vuxu.org/musl/20210821085420.474615-3-hi@alyssa.is/
Previously I had a second, optional patch, that would have tested the
behavior of a single-field mntent entry. I've dropped that one, because
musl chose not to match Glibc in accepting it.
AUTHORS | 1 +
src/functional/mntent.c | 76 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
create mode 100644 src/functional/mntent.c
diff --git a/AUTHORS b/AUTHORS
index ff99471..cf2a394 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,3 +5,4 @@ John Spencer
Jens Gustedt
Alexander Monakov
Julien Ramseier
+Alyssa Ross
diff --git a/src/functional/mntent.c b/src/functional/mntent.c
new file mode 100644
index 0000000..59d816a
--- /dev/null
+++ b/src/functional/mntent.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: MIT
+
+#define _DEFAULT_SOURCE // for getmntent_r
+
+#include <mntent.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "test.h"
+
+#define ASSERT(x) do { \
+ if (!(x)) { \
+ t_error(#x " failed\n"); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0);
+
+#define ERR(fmt, ...) do { \
+ t_error(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+
+void test_getmntent_empty(void)
+{
+ char fstab[] = "\n";
+ FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
+ if (!f) ERR("fmemopen");
+ ASSERT(!getmntent(f));
+ ASSERT(endmntent(f) == 1);
+}
+
+void test_getmntent(void)
+{
+ // Checks that the fifth and sixth fields default to 0.
+ char fstab[] = "none /proc proc defaults\n";
+ FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
+ if (!f) ERR("fmemopen");
+ struct mntent *m = getmntent(f);
+ ASSERT(m);
+ ASSERT(!strcmp(m->mnt_fsname, "none"));
+ ASSERT(!strcmp(m->mnt_dir, "/proc"));
+ ASSERT(!strcmp(m->mnt_type, "proc"));
+ ASSERT(!strcmp(m->mnt_opts, "defaults"));
+ ASSERT(m->mnt_freq == 0);
+ ASSERT(m->mnt_passno == 0);
+ ASSERT(endmntent(f) == 1);
+}
+
+void test_getmntent_r(void)
+{
+ struct mntent m, *r;
+ char fstab[] = "/dev/sda\t/\text4\trw,nosuid\t2\t1\n";
+ char buf[sizeof(fstab)];
+
+ FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
+ if (!f) ERR("fmemopen");
+
+ r = getmntent_r(f, &m, buf, sizeof buf);
+ ASSERT(r == &m);
+ ASSERT(!strcmp(m.mnt_fsname, "/dev/sda"));
+ ASSERT(!strcmp(m.mnt_dir, "/"));
+ ASSERT(!strcmp(m.mnt_type, "ext4"));
+ ASSERT(!strcmp(m.mnt_opts, "rw,nosuid"));
+ ASSERT(m.mnt_freq == 2);
+ ASSERT(m.mnt_passno == 1);
+ ASSERT(endmntent(f) == 1);
+}
+
+int main(void)
+{
+ test_getmntent_empty();
+ test_getmntent();
+ test_getmntent_r();
+}
base-commit: a07fb60c4996955216ef9a331dae124374984b3a
--
2.46.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH libc-test v3] functional: add mntent test
2024-10-19 18:16 [musl] [PATCH libc-test v3] functional: add mntent test Alyssa Ross
@ 2024-10-22 10:03 ` Szabolcs Nagy
2024-10-22 12:12 ` Alyssa Ross
0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2024-10-22 10:03 UTC (permalink / raw)
To: Alyssa Ross; +Cc: musl
* Alyssa Ross <hi@alyssa.is> [2024-10-19 20:16:39 +0200]:
> This only checks reading an fstab from an stream. I haven't written
> tests for setmntent(), addmntent(), or hasmntnent().
>
> test_getmntent exposes a bug in musl 1.2.3 where lines omitting the
> final two fields, which are supposed to be optional according to
> fstab(5), are not accepted. It also exposes a current bug, where if
> the numeric fields are omitted, the last field seen will have a
> newline appended to its value. The tests all pass on Glibc.
> ---
> v3: updated description for current musl
> v2: https://inbox.vuxu.org/musl/20210821085420.474615-3-hi@alyssa.is/
>
> Previously I had a second, optional patch, that would have tested the
> behavior of a single-field mntent entry. I've dropped that one, because
> musl chose not to match Glibc in accepting it.
>
patch looks ok. it fails with
src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
FAIL src/functional/mntent-static.exe [status 1]
src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
FAIL src/functional/mntent.exe [status 1]
i guess this should be fixed
i'd factor the test slightly differently but it is also ok as is.
i wait a bit before applyin it, to see if it gets fixed in musl.
(e.g. it could have
static struct mntent *t_getmntent(char *fstab, int use_r);
and then
for (i=0; i<2; i++) {
m = t_getmntent("\n", i);
ASSERT(!m);
m = t_getmntent("none /proc proc defaults\n", i);
ASSERT(m);
ASSERT(!strcmp(m->mnt_fsname, "none"));
...
m = t_getmntent("/dev/sda\t/\text4\trw,nosuid\t2\t1\n", i);
...
}
and normally i avoid exitin early on failure if continuing the tests
is possible, so then multiple failures are all reported. t_error sets
t_status so you can just return t_status at the end of main.)
> AUTHORS | 1 +
> src/functional/mntent.c | 76 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 77 insertions(+)
> create mode 100644 src/functional/mntent.c
>
> diff --git a/AUTHORS b/AUTHORS
> index ff99471..cf2a394 100644
> --- a/AUTHORS
> +++ b/AUTHORS
> @@ -5,3 +5,4 @@ John Spencer
> Jens Gustedt
> Alexander Monakov
> Julien Ramseier
> +Alyssa Ross
> diff --git a/src/functional/mntent.c b/src/functional/mntent.c
> new file mode 100644
> index 0000000..59d816a
> --- /dev/null
> +++ b/src/functional/mntent.c
> @@ -0,0 +1,76 @@
> +// SPDX-License-Identifier: MIT
> +
> +#define _DEFAULT_SOURCE // for getmntent_r
> +
> +#include <mntent.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <errno.h>
> +
> +#include "test.h"
> +
> +#define ASSERT(x) do { \
> + if (!(x)) { \
> + t_error(#x " failed\n"); \
> + exit(EXIT_FAILURE); \
> + } \
> + } while (0);
> +
> +#define ERR(fmt, ...) do { \
> + t_error(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); \
> + exit(EXIT_FAILURE); \
> + } while (0)
> +
> +void test_getmntent_empty(void)
> +{
> + char fstab[] = "\n";
> + FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
> + if (!f) ERR("fmemopen");
> + ASSERT(!getmntent(f));
> + ASSERT(endmntent(f) == 1);
> +}
> +
> +void test_getmntent(void)
> +{
> + // Checks that the fifth and sixth fields default to 0.
> + char fstab[] = "none /proc proc defaults\n";
> + FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
> + if (!f) ERR("fmemopen");
> + struct mntent *m = getmntent(f);
> + ASSERT(m);
> + ASSERT(!strcmp(m->mnt_fsname, "none"));
> + ASSERT(!strcmp(m->mnt_dir, "/proc"));
> + ASSERT(!strcmp(m->mnt_type, "proc"));
> + ASSERT(!strcmp(m->mnt_opts, "defaults"));
> + ASSERT(m->mnt_freq == 0);
> + ASSERT(m->mnt_passno == 0);
> + ASSERT(endmntent(f) == 1);
> +}
> +
> +void test_getmntent_r(void)
> +{
> + struct mntent m, *r;
> + char fstab[] = "/dev/sda\t/\text4\trw,nosuid\t2\t1\n";
> + char buf[sizeof(fstab)];
> +
> + FILE *f = fmemopen((void *)fstab, sizeof fstab - 1, "r");
> + if (!f) ERR("fmemopen");
> +
> + r = getmntent_r(f, &m, buf, sizeof buf);
> + ASSERT(r == &m);
> + ASSERT(!strcmp(m.mnt_fsname, "/dev/sda"));
> + ASSERT(!strcmp(m.mnt_dir, "/"));
> + ASSERT(!strcmp(m.mnt_type, "ext4"));
> + ASSERT(!strcmp(m.mnt_opts, "rw,nosuid"));
> + ASSERT(m.mnt_freq == 2);
> + ASSERT(m.mnt_passno == 1);
> + ASSERT(endmntent(f) == 1);
> +}
> +
> +int main(void)
> +{
> + test_getmntent_empty();
> + test_getmntent();
> + test_getmntent_r();
> +}
>
> base-commit: a07fb60c4996955216ef9a331dae124374984b3a
> --
> 2.46.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH libc-test v3] functional: add mntent test
2024-10-22 10:03 ` Szabolcs Nagy
@ 2024-10-22 12:12 ` Alyssa Ross
2024-10-22 16:36 ` Rich Felker
0 siblings, 1 reply; 5+ messages in thread
From: Alyssa Ross @ 2024-10-22 12:12 UTC (permalink / raw)
To: Szabolcs Nagy; +Cc: musl
[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]
Szabolcs Nagy <nsz@port70.net> writes:
> * Alyssa Ross <hi@alyssa.is> [2024-10-19 20:16:39 +0200]:
>> This only checks reading an fstab from an stream. I haven't written
>> tests for setmntent(), addmntent(), or hasmntnent().
>>
>> test_getmntent exposes a bug in musl 1.2.3 where lines omitting the
>> final two fields, which are supposed to be optional according to
>> fstab(5), are not accepted. It also exposes a current bug, where if
>> the numeric fields are omitted, the last field seen will have a
>> newline appended to its value. The tests all pass on Glibc.
>> ---
>> v3: updated description for current musl
>> v2: https://inbox.vuxu.org/musl/20210821085420.474615-3-hi@alyssa.is/
>>
>> Previously I had a second, optional patch, that would have tested the
>> behavior of a single-field mntent entry. I've dropped that one, because
>> musl chose not to match Glibc in accepting it.
>>
>
> patch looks ok. it fails with
>
> src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> FAIL src/functional/mntent-static.exe [status 1]
> src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> FAIL src/functional/mntent.exe [status 1]
>
> i guess this should be fixed
Fix has already been submitted here:
https://inbox.vuxu.org/musl/20241019181320.23977-2-hi@alyssa.is/
I think it should pass on musl 1.2.4.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH libc-test v3] functional: add mntent test
2024-10-22 12:12 ` Alyssa Ross
@ 2024-10-22 16:36 ` Rich Felker
2024-10-22 22:17 ` Szabolcs Nagy
0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2024-10-22 16:36 UTC (permalink / raw)
To: Alyssa Ross; +Cc: Szabolcs Nagy, musl
On Tue, Oct 22, 2024 at 02:12:52PM +0200, Alyssa Ross wrote:
> Szabolcs Nagy <nsz@port70.net> writes:
>
> > * Alyssa Ross <hi@alyssa.is> [2024-10-19 20:16:39 +0200]:
> >> This only checks reading an fstab from an stream. I haven't written
> >> tests for setmntent(), addmntent(), or hasmntnent().
> >>
> >> test_getmntent exposes a bug in musl 1.2.3 where lines omitting the
> >> final two fields, which are supposed to be optional according to
> >> fstab(5), are not accepted. It also exposes a current bug, where if
> >> the numeric fields are omitted, the last field seen will have a
> >> newline appended to its value. The tests all pass on Glibc.
> >> ---
> >> v3: updated description for current musl
> >> v2: https://inbox.vuxu.org/musl/20210821085420.474615-3-hi@alyssa.is/
> >>
> >> Previously I had a second, optional patch, that would have tested the
> >> behavior of a single-field mntent entry. I've dropped that one, because
> >> musl chose not to match Glibc in accepting it.
> >>
> >
> > patch looks ok. it fails with
> >
> > src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> > FAIL src/functional/mntent-static.exe [status 1]
> > src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> > FAIL src/functional/mntent.exe [status 1]
> >
> > i guess this should be fixed
>
> Fix has already been submitted here:
> https://inbox.vuxu.org/musl/20241019181320.23977-2-hi@alyssa.is/
>
> I think it should pass on musl 1.2.4.
Yep, thanks. I'll get this and some other new stuff committed.
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH libc-test v3] functional: add mntent test
2024-10-22 16:36 ` Rich Felker
@ 2024-10-22 22:17 ` Szabolcs Nagy
0 siblings, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2024-10-22 22:17 UTC (permalink / raw)
To: Rich Felker; +Cc: Alyssa Ross, musl
* Rich Felker <dalias@libc.org> [2024-10-22 12:36:29 -0400]:
> On Tue, Oct 22, 2024 at 02:12:52PM +0200, Alyssa Ross wrote:
> > Szabolcs Nagy <nsz@port70.net> writes:
> >
> > > * Alyssa Ross <hi@alyssa.is> [2024-10-19 20:16:39 +0200]:
> > >> This only checks reading an fstab from an stream. I haven't written
> > >> tests for setmntent(), addmntent(), or hasmntnent().
> > >>
> > >> test_getmntent exposes a bug in musl 1.2.3 where lines omitting the
> > >> final two fields, which are supposed to be optional according to
> > >> fstab(5), are not accepted. It also exposes a current bug, where if
> > >> the numeric fields are omitted, the last field seen will have a
> > >> newline appended to its value. The tests all pass on Glibc.
> > >> ---
> > >> v3: updated description for current musl
> > >> v2: https://inbox.vuxu.org/musl/20210821085420.474615-3-hi@alyssa.is/
> > >>
> > >> Previously I had a second, optional patch, that would have tested the
> > >> behavior of a single-field mntent entry. I've dropped that one, because
> > >> musl chose not to match Glibc in accepting it.
> > >>
> > >
> > > patch looks ok. it fails with
> > >
> > > src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> > > FAIL src/functional/mntent-static.exe [status 1]
> > > src/functional/mntent.c:47: !strcmp(m->mnt_opts, "defaults") failed
> > > FAIL src/functional/mntent.exe [status 1]
> > >
> > > i guess this should be fixed
> >
> > Fix has already been submitted here:
> > https://inbox.vuxu.org/musl/20241019181320.23977-2-hi@alyssa.is/
> >
> > I think it should pass on musl 1.2.4.
>
> Yep, thanks. I'll get this and some other new stuff committed.
ok. i committed the libc-test patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-22 22:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-19 18:16 [musl] [PATCH libc-test v3] functional: add mntent test Alyssa Ross
2024-10-22 10:03 ` Szabolcs Nagy
2024-10-22 12:12 ` Alyssa Ross
2024-10-22 16:36 ` Rich Felker
2024-10-22 22:17 ` Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).