[Tarantool-patches] [PATCH luajit 2/2] test: rewrite sysprof test using managed execution

Igor Munkin imun at tarantool.org
Tue Dec 5 15:59:01 MSK 2023


Sergey,

On 05.12.23, Sergey Kaplun wrote:
> Hi, Igor!
> Thanks for the fixes!
> Please, consider my comments below.
> 

<snipped>

> 
> > 
> > > 
> > > > > +#define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
> > > > > +#define DEVNULL -1
> > > 
> > > `DEVNULL` name is misleading (like we've actually opened `/dev/null`).
> > > Maybe `DUMMY_FD` is better? Also, I suppose we can drop the `fd` field
> > > at all. We can just use static structure in this translation unit and
> > > compare pointer against it, so there is no need for an additional field
> > > fd in the structure itself.
> > 
> > I see little reasoning in this suggestion: the approach with the
> > structure is quite straight-forward and copied from another sysprof test
> > implemented in C. Re naming: I prefer to leave it as is.
> 
> I don't get why it is straight-forward. This approach with unused fields
> is just misleading. In
> <test/tarantool-c-tests/misclib-sysprof-capi.test.c> the `fd` field is
> used since the "/dev/null" is opened and data written to it.
> 
> Also, since we can use custom writer, that test may be updated wo using
> `fd` too. But this should be done as a separate refactoring patch.
> 
> > 
> > In general, your nit is nice, but I believe it should be applied
> > for the patch moving <ptrace> tricks to utils library.
> 
> I don't see any relations with ptrace here. It's just the usage of
> sysprof's C API.

Well, I've finally got your original idea. Here it is:

================================================================================

diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
index 6bf7562f..8967abc4 100644
--- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
+++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
@@ -53,35 +53,26 @@
 extern void *lj_ff_tostring(void);
 extern void *lj_fff_res1(void);
 
-/* Sysprof "/dev/null" stream helpers. {{{ */
+/* Sysprof dummy stream helpers. {{{ */
 
 /*
  * Yep, 8Mb. Tuned in order not to bother the platform with too
  * often flushes.
  */
 #define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
-#define DEVNULL -1
 
-struct devnull_ctx {
-	/*
-	 * XXX: Dummy file descriptor to be used as "/dev/null"
-	 * context indicator in writer and on_stop callback.
-	 */
-	int fd;
+struct dummy_ctx {
 	/* Buffer for data recorded by sysprof. */
 	uint8_t buf[STREAM_BUFFER_SIZE];
 };
 
+static struct dummy_ctx context;
+
 static int stream_new(struct luam_Sysprof_Options *options)
 {
-	struct devnull_ctx *ctx = calloc(1, sizeof(struct devnull_ctx));
-	if (ctx == NULL)
-		return PROFILE_ERRIO;
-
-	/* Set "/dev/null" context indicator. */
-	ctx->fd = DEVNULL;
-	options->ctx = ctx;
-	options->buf = ctx->buf;
+	/* Set dummy context. */
+	options->ctx = &context;
+	options->buf = (uint8_t *)&context.buf;
 	options->len = STREAM_BUFFER_SIZE;
 
 	return PROFILE_SUCCESS;
@@ -89,21 +80,19 @@ static int stream_new(struct luam_Sysprof_Options *options)
 
 static int stream_delete(void *rawctx, uint8_t *buf)
 {
-	struct devnull_ctx *ctx = rawctx;
-	assert(ctx->fd == DEVNULL);
-	free(ctx);
+	assert(rawctx == &context);
+	/* XXX: No need to release context memory. Just return. */
 	return PROFILE_SUCCESS;
 }
 
 static size_t stream_writer(const void **buf_addr, size_t len, void *rawctx)
 {
-	struct devnull_ctx *ctx = rawctx;
-	assert(ctx->fd == DEVNULL);
+	assert(rawctx == &context);
 	/* Do nothing, just return back to the profiler. */
 	return STREAM_BUFFER_SIZE;
 }
 
-/* }}} Sysprof "/dev/null" stream helpers. */
+/* }}} Sysprof dummy stream helpers. */
 
 static int tracee(const char *luacode)
 {

================================================================================

> 

<snipped>

> 
> > > 
> > > Typo: s/<lj_fff_res1>/the <lj_fff_res1>/
> > > 
> > > > > +	 * FIXME: Make this part test agnostic.
> > > 
> > > Typo: s/test agnostic/test-agnostic/
> > > 
> > > Nit: TODO looks more valid for me (since it's working).
> > > Feel free to ignore.
> > 
> > Fixed.
> > 
> > ================================================================================
> > 
> > diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > index 44421812..036f8141 100644
> > --- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > +++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > @@ -153,8 +153,8 @@ static int tracee(const char *luacode)
> >  
> >  	/*
> >  	 * XXX: The only event to be streamed must be FFUNC at
> > -	 * <lj_fff_res1> instruction.
> > -	 * FIXME: Make this part test agnostic.
> > +	 * the <lj_fff_res1> instruction.
> > +	 * TODO: Make this part test agnostic.
> 
> Typo: s/test agnostic/test-agnostic/

Fixed (again).

================================================================================

diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
index 8967abc4..a1c4a3ed 100644
--- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
+++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
@@ -143,7 +143,7 @@ static int tracee(const char *luacode)
 	/*
 	 * XXX: The only event to be streamed must be FFUNC at
 	 * the <lj_fff_res1> instruction.
-	 * TODO: Make this part test agnostic.
+	 * TODO: Make this part test-agnostic.
 	 */
 	assert(luaM_sysprof_report(&counters) == PROFILE_SUCCESS);
 	assert(counters.samples == 1);

================================================================================

> 

<snipped>

> > > -- 
> > > Best regards,
> > > Sergey Kaplun
> > 
> > -- 
> > Best regards,
> > IM
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM


More information about the Tarantool-patches mailing list