[6.0] 2f6d9be42 varnishtest: Turn the ${date} macro into a function

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Thu Apr 4 14:33:07 UTC 2024


commit 2f6d9be42ee56ffc6654c0b02baa9238572b09e0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Jun 17 16:10:16 2021 +0200

    varnishtest: Turn the ${date} macro into a function
    
    Conflicts:
            bin/varnishtest/vtc.c

diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 87ee0055b..4b1d415ff 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -41,7 +41,6 @@
 
 #include "vav.h"
 #include "vrnd.h"
-#include "vtim.h"
 
 #define		MAX_TOKENS		200
 
@@ -224,17 +223,6 @@ macro_cat(struct vtclog *vl, struct vsb *vsb, const char *b, const char *e)
 
 	assert(argc >= 2);
 
-	if (!strcmp(argv[1], "date")) {
-		double t = VTIM_real();
-		retval = malloc(64);
-		AN(retval);
-		VTIM_format(t, retval);
-		VSB_cat(vsb, retval);
-		free(retval);
-		VAV_Free(argv);
-		return;
-	}
-
 	AZ(pthread_mutex_lock(&macro_mtx));
 	VTAILQ_FOREACH(m, &macro_list, list) {
 		CHECK_OBJ_NOTNULL(m, MACRO_MAGIC);
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index ca263aa61..e2ccbef24 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -597,6 +597,32 @@ ip_magic(void)
 	extmacro_def("bad_ip", NULL, "%s", "192.0.2.255");
 }
 
+/**********************************************************************
+ * Macros
+ */
+
+static char * v_matchproto_(macro_f)
+macro_func_date(int argc, char *const *argv, const char **err)
+{
+	double t;
+	char *s;
+
+	assert(argc >= 2);
+	AN(argv);
+	AN(err);
+
+	if (argc > 2) {
+		*err = "macro does not take arguments";
+		return (NULL);
+	}
+
+	t = VTIM_real();
+	s = malloc(VTIM_FORMAT_SIZE);
+	AN(s);
+	VTIM_format(t, s);
+	return (s);
+}
+
 /**********************************************************************
  * Main
  */
@@ -676,6 +702,8 @@ main(int argc, char * const *argv)
 	cwd = getcwd(buf, sizeof buf);
 	extmacro_def("pwd", NULL, "%s", cwd);
 
+	extmacro_def("date", macro_func_date, NULL);
+
 	vmod_path = NULL;
 
 	params_vsb = VSB_new_auto();


More information about the varnish-commit mailing list