improved base and added PP defines KERNEL_UPSTREAM TESTING DEBUG
This commit is contained in:
35
um/test/Makefile
Normal file
35
um/test/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
# Define the name of your application
|
||||
APP_NAME = test_app
|
||||
|
||||
# Source files for your application
|
||||
APP_SRCS = main.cpp
|
||||
APP_OBJS = $(APP_SRCS:.cpp=.o)
|
||||
|
||||
# Compiler and compiler flags
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -Werror -fexceptions
|
||||
|
||||
# Library name and source files
|
||||
LIB_NAME = libmath_module.so
|
||||
LIB_SRCS = math_module.cpp
|
||||
LIB_OBJS = $(LIB_SRCS:.cpp=.o)
|
||||
|
||||
# Additional flags for creating PIC code
|
||||
PICFLAGS = -fPIC
|
||||
|
||||
# The default target is 'all', which builds your application
|
||||
all: $(APP_NAME) $(LIB_NAME)
|
||||
|
||||
$(APP_NAME): $(APP_OBJS) $(LIB_NAME)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $(APP_OBJS) -L. -lmath_module -Wl,-rpath,'$$ORIGIN'
|
||||
|
||||
$(LIB_NAME): $(LIB_OBJS)
|
||||
$(CXX) -shared -o $@ $(LIB_OBJS) $(CXXFLAGS)
|
||||
|
||||
# Compile source files to object files
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(PICFLAGS) -c $< -o $@
|
||||
|
||||
# Clean rule to remove the executable, object files, and library
|
||||
clean:
|
||||
rm -f $(APP_NAME) $(APP_OBJS) $(LIB_NAME) $(LIB_OBJS)
|
||||
1
um/test/addr.txt
Normal file
1
um/test/addr.txt
Normal file
@@ -0,0 +1 @@
|
||||
0x7fff7203ed94
|
||||
44
um/test/main.cpp
Normal file
44
um/test/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <cstdint>
|
||||
|
||||
#include "math_module.h"
|
||||
|
||||
int main() {
|
||||
MathModule math;
|
||||
|
||||
int result = math.add(10, 5);
|
||||
std::cout << "10 + 5 = " << result << std::endl;
|
||||
|
||||
result = math.subtract(10, 5);
|
||||
std::cout << "10 - 5 = " << result << std::endl;
|
||||
|
||||
result = math.multiply(10, 5);
|
||||
std::cout << "10 * 5 = " << result << std::endl;
|
||||
|
||||
double divisionResult = math.divide(10.0, 5.0);
|
||||
std::cout << "10 / 5 = " << divisionResult << std::endl;
|
||||
|
||||
|
||||
int var = 0;
|
||||
uint64_t* var_virtaddr = reinterpret_cast<uint64_t*>(&var);
|
||||
std::ofstream outFile("addr.txt");
|
||||
if (!outFile.is_open()) {
|
||||
std::cerr << "Error: Could not open the file for writing." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
outFile << var_virtaddr;
|
||||
outFile.close();
|
||||
|
||||
while (true) {
|
||||
int random_increment = std::rand() % 100; // Generate a random number between 0 and 99
|
||||
std::cout << "before inc value=" << std::dec << var << "@" << std::hex << var_virtaddr << std::endl;
|
||||
var += random_increment;
|
||||
std::cout << "after inc value=" << std::dec << var << "@" << std::hex << var_virtaddr << std::endl;
|
||||
std::cin.get(); // Wait for Enter key press
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
|
||||
24
um/test/math_module.cpp
Normal file
24
um/test/math_module.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "math_module.h"
|
||||
|
||||
MathModule::MathModule() {
|
||||
// Constructor, if any initialization is needed
|
||||
}
|
||||
|
||||
int MathModule::add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int MathModule::subtract(int a, int b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
int MathModule::multiply(int a, int b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
double MathModule::divide(double a, double b) {
|
||||
if (b == 0) {
|
||||
throw "Division by zero is not allowed.";
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
14
um/test/math_module.h
Normal file
14
um/test/math_module.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MATH_MODULE_H
|
||||
#define MATH_MODULE_H
|
||||
|
||||
class MathModule {
|
||||
public:
|
||||
MathModule(); // Constructor
|
||||
|
||||
int add(int a, int b);
|
||||
int subtract(int a, int b);
|
||||
int multiply(int a, int b);
|
||||
double divide(double a, double b);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user