Ver Fonte

add tests with shrtcut

fanch há 1 ano atrás
pai
commit
4fcd83847b
6 ficheiros alterados com 181 adições e 2 exclusões
  1. 51 0
      tests/plugins/test_plugins_1.cpp
  2. 4 0
      tests/plugins/wscript
  3. 15 0
      tests/tests.h
  4. 4 0
      tests/wscript
  5. 27 0
      waftools/__init__.py
  6. 80 2
      wscript

+ 51 - 0
tests/plugins/test_plugins_1.cpp

@@ -0,0 +1,51 @@
+#include "tests.h"
+
+waf_test_use("plugin_base")
+
+#include "core/PluginIndex.h"
+#include "core/PluginManager.h"
+#include "io/FileSoundInput.h"
+
+struct TestPlugin {
+	TestPlugin() {
+
+	}
+
+	PluginIndex host;
+	PluginManager manager;
+
+};
+
+
+#define SAMPLE_WINDOW 4096
+int main(int argc, char** argv){
+	try {
+		TestPlugin plugins;
+		plugins.host.add_path("/home/fanch/Programmation/audio_renderer/debug/src/plugins/");
+		//plugins.host.add_path("/usr/lib/ladspa");
+		plugins.host.update();
+		PluginEntry& plugin = plugins.host.load_from_path("/home/fanch/Programmation/audio_renderer/debug/src/plugins/libaudio_to_midi.so");
+		//printf("Add plugin\n");
+		FileSoundInput fsi("/home/fanch/Programmation/LADSPA/audio_to_midi/snd/yafs1.wav", SAMPLE_WINDOW);
+
+		plugins.manager.set_rate(44100, SAMPLE_WINDOW);
+		plugins.manager.add_plugin(plugin);
+
+
+		LADSPA_Data* buffer = plugins.manager.get_input();
+		int count = 0;
+		while ((buffer = fsi.next(buffer))){
+			plugins.manager.run(buffer);
+			count ++;
+			if(count>1000){
+				break;
+			}
+		}
+		printf("fin\n");
+		delete[] buffer;
+
+	} catch (const char* x) {
+		printf("Erreur: %s\n", x);
+	}
+
+}

+ 4 - 0
tests/plugins/wscript

@@ -0,0 +1,4 @@
+
+
+def build(bld):
+    bld.find_test()

+ 15 - 0
tests/tests.h

@@ -0,0 +1,15 @@
+/*
+ * tests.h
+ *
+ *  Created on: 23 déc. 2023
+ *      Author: fanch
+ */
+
+#ifndef TESTS_TESTS_H_
+#define TESTS_TESTS_H_
+
+#define waf_test_use(...)
+
+
+
+#endif /* TESTS_TESTS_H_ */

+ 4 - 0
tests/wscript

@@ -0,0 +1,4 @@
+
+
+def build(bld):
+    bld.find_test()

+ 27 - 0
waftools/__init__.py

@@ -0,0 +1,27 @@
+from pathlib import Path
+import re
+class TestRecognizer:
+    RE_FIND_WAF_INFO = re.compile(r"[^\w]waf_test_[A-Za-z0-9_]+\(")
+    
+    def __init__(self, bld, file):
+        self.bld = bld
+        self.file = file
+    
+    def recognize(self, content, reco):
+        print(content, reco)
+        exit(-1)
+    
+    def add_test(self):
+        content = Path(self.file).read_text()
+        for x in self.RE_FIND_WAF_INFO.findall(content):
+            self.recognize(content, x)
+
+def find_test(bld, dir):
+    for file in Path(dir).iterdir():
+        if file.is_file() and file.name.endswith(".cpp"):
+            TestRecognizer(bld, file).add_test()
+        elif file.is_dir() and (file / "wscript").is_file():
+            bld.recurse(file.name)
+
+    
+    

+ 80 - 2
wscript

@@ -1,7 +1,6 @@
 #! /usr/bin/env python
 # encoding: utf-8
 # Thomas Nagy, 2006-2010 (ita)
-
 # the following two variables are used by the target "waf dist"
 VERSION='0.0.1'
 APPNAME='cxx_test'
@@ -10,11 +9,88 @@ APPNAME='cxx_test'
 top = '.'
 out = 'debug'
 
-
+import re
 
 from functools import partial
 from pathlib import Path
 
+
+class TestRecognizer:
+    RE_FIND_WAF_INFO = re.compile(r"[^\w]waf_test_[A-Za-z0-9_]+\(")
+    
+    def __init__(self, bld, file):
+        self.bld = bld
+        self.file = Path(file)
+        self.root = Path(str(bld.top_dir))
+        self.src_dir = self.root / "src"
+        self.tests_dir = self.root / "tests"
+        self.target = {
+            "source" : [self.file.name],
+            "target" : self.file.name.replace(".cpp", ""),
+            "includes" : [".", "..", str(self.src_dir), str(self.tests_dir)],
+            "lib" : ["SDL2", "SDL2_image", "fftw3", "sndfile"],
+            "use" : ["io", "core", ]
+            
+        }
+    
+    def recognize(self, content, reco):
+        start = reco.regs[0][0]+1
+        curr = start
+        while content[curr] != "(":
+            curr +=1
+            
+        function = content[start : curr].strip(" \n\t")
+        start = curr
+        curr += 1
+        count = 1
+        while count>0:
+            if content[curr] == ")":
+                count-=1
+            if content[curr] == "(":
+                count+=1
+            curr +=1
+        args = content[start:curr+1]
+        args = eval(args)
+        if not isinstance(args, (tuple, list)):
+            args = [args]
+        args = list(args)
+        f_name = f"execute_{function[9:]}"
+        if not hasattr(self, f_name):
+            nb = len(content[:start].split("\n")) + 1
+            raise ValueError(f"Fichier {self.file} ligne {nb} waf_test_{f_name} est inconnu")
+        getattr(self, f_name)(args)
+    
+    def _add_or_append(self, k, v):
+        if k not in self.target:
+            self.target[k] = []
+        
+        if not isinstance(self.target[k], list):
+            self.target[k] = [*(self.target[k].split(" "))]
+        self.target[k].extend(v)
+    
+    def execute_use(self, data):
+        self._add_or_append("use", data)
+    
+    def add_test(self):
+        content = Path(self.file).read_text()
+        for x in self.RE_FIND_WAF_INFO.finditer(content):
+            self.recognize(content, x)
+        
+        print(f"add program :  {self.target}")
+        self.bld.program(**self.target)
+
+def find_test(bld):
+    dir = str(bld.path)
+    for file in Path(dir).iterdir():
+        if file.is_file() and file.name.endswith(".cpp"):
+            TestRecognizer(bld, file).add_test()
+        elif file.is_dir() and (file / "wscript").is_file():
+            bld.recurse(file.name)
+
+    
+
+
+
 def get_sub_files(obj, suffixes=(".c", ".cpp", ".cxx"), max_depth=None):
     root = Path(str(obj.path))
     if root.is_file():
@@ -46,12 +122,14 @@ def configure(conf):
     conf.check(header_name='stdio.h', features='cxx cxxprogram', mandatory=False)
 
 def build(bld):
+    bld.find_test = partial(find_test, bld)
     bld.get_sub_files = partial(get_sub_files, bld)
     bld.recurse("src/common")
     bld.recurse("src/core")
     bld.recurse("src/fft")
     bld.recurse("src/io")
     bld.recurse("src/plugins")
+    bld.recurse("tests")
     bld.program(target=APPNAME, 
                 features='cxx cxxprogram',
                 lib=['fftw3', "sndfile"],