Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Synchronize Node.js binding version
run: |
echo "Synchronizing Node.js binding version with main project..."
python3 scripts/sync_node_version.py

- name: Get package version
id: package
working-directory: libCacheSim-node
Expand Down Expand Up @@ -81,6 +86,11 @@ jobs:
with:
fetch-depth: 0

- name: Synchronize Node.js binding version
run: |
echo "Synchronizing Node.js binding version with main project..."
python3 scripts/sync_node_version.py

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -140,6 +150,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Synchronize Node.js binding version
run: |
echo "Synchronizing Node.js binding version with main project..."
python3 scripts/sync_node_version.py

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ project(libCacheSim)
set(DESCRIPTION "a high performance cache simulation library")
set(PROJECT_WEB "http://cachesim.com")

set(${PROJECT_NAME}_VERSION_MAJOR 0)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_RELEASE_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR})
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_RELEASE_VERSION}.${${PROJECT_NAME}_VERSION_PATCH})
# Include version utilities
include(cmake/Version.cmake)

# Setup version from version.txt
setup_project_version(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
Expand Down
54 changes: 47 additions & 7 deletions cmake/Version.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
# Version parsing utilities for libCacheSim
# Based on xgboost version handling

# from xgboost
function (write_version)
message(STATUS "xgboost VERSION: ${xgboost_VERSION}")
configure_file(
${xgboost_SOURCE_DIR}/include/config.h.in
${xgboost_SOURCE_DIR}/include/config.h @ONLY)
function(parse_version_from_file VERSION_FILE VERSION_MAJOR_VAR VERSION_MINOR_VAR VERSION_PATCH_VAR)
if(EXISTS "${VERSION_FILE}")
file(READ "${VERSION_FILE}" VERSION_STRING)
string(STRIP "${VERSION_STRING}" VERSION_STRING)

# Parse MAJOR.MINOR.PATCH format
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" VERSION_MATCH "${VERSION_STRING}")
if(VERSION_MATCH)
set(${VERSION_MAJOR_VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
set(${VERSION_MINOR_VAR} ${CMAKE_MATCH_2} PARENT_SCOPE)
set(${VERSION_PATCH_VAR} ${CMAKE_MATCH_3} PARENT_SCOPE)
message(STATUS "Version from ${VERSION_FILE}: ${VERSION_STRING}")
else()
message(FATAL_ERROR "Invalid version format in ${VERSION_FILE}: ${VERSION_STRING}. Expected format: MAJOR.MINOR.PATCH")
endif()
else()
message(FATAL_ERROR "Version file not found: ${VERSION_FILE}")
endif()
endfunction()

function(setup_project_version PROJECT_NAME VERSION_FILE)
if(EXISTS "${VERSION_FILE}")
parse_version_from_file("${VERSION_FILE}" VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
set(${PROJECT_NAME}_VERSION_MAJOR ${VERSION_MAJOR} PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION_MINOR ${VERSION_MINOR} PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION_PATCH ${VERSION_PATCH} PARENT_SCOPE)
set(${PROJECT_NAME}_RELEASE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR} PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} PARENT_SCOPE)
else()
message(STATUS "${VERSION_FILE} not found, using default version")
set(${PROJECT_NAME}_VERSION_MAJOR 0 PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION_MINOR 1 PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION_PATCH 0 PARENT_SCOPE)
set(${PROJECT_NAME}_RELEASE_VERSION 0.1 PARENT_SCOPE)
set(${PROJECT_NAME}_VERSION 0.1.0 PARENT_SCOPE)
endif()
endfunction()

# Legacy function for xgboost compatibility
function(write_version)
message(STATUS "xgboost VERSION: ${xgboost_VERSION}")
configure_file(
${xgboost_SOURCE_DIR}/include/config.h.in
${xgboost_SOURCE_DIR}/include/config.h @ONLY)
# configure_file(
# ${xgboost_SOURCE_DIR}/cmake/Python_version.in
# ${xgboost_SOURCE_DIR}/python-package/xgboost/VERSION @ONLY)
endfunction (write_version)
endfunction(write_version)
19 changes: 19 additions & 0 deletions libCacheSim-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ console.log('Simulation results:', result);

## API Reference

### `getVersion()`

Get the version of the libCacheSim Node.js binding.

**Returns:** String containing the version number (e.g., "1.0.1")

### `runSimulation(tracePath, traceType, algorithm, cacheSize)`

Run a cache simulation with specified parameters.
Expand Down Expand Up @@ -100,6 +106,9 @@ npm install -g libcachesim-node

# Run simulation from command line
cachesim-js --trace /path/to/trace.vscsi --algorithm s3fifo --size 1mb

# Check version
cachesim-js --version
```

## Development
Expand Down Expand Up @@ -132,6 +141,16 @@ npm test
- Linux: `build-essential cmake libglib2.0-dev libzstd-dev`
- macOS: `cmake glib zstd` (via Homebrew)

### Version Synchronization

The Node.js binding version is automatically synchronized with the main libCacheSim project version. To manually sync versions, run:

```bash
python3 scripts/sync_node_version.py
```

This ensures that the Node.js binding version in `package.json` matches the version in the main project's `version.txt` file.

## Architecture

This package uses `prebuild-install` for binary distribution:
Expand Down
13 changes: 12 additions & 1 deletion libCacheSim-node/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function parseArgs() {
type: null,
algorithm: null,
size: null,
help: false
help: false,
version: false
};

for (let i = 0; i < args.length; i++) {
Expand All @@ -35,6 +36,10 @@ function parseArgs() {
case '-h':
options.help = true;
break;
case '--version':
case '-v':
options.version = true;
break;
default:
console.error(`Unknown option: ${args[i]}`);
process.exit(1);
Expand All @@ -60,6 +65,7 @@ Options:
--size, -s <size> Cache size (required)
Examples: 1mb, 512kb, 2gb, 1024 (bytes)
--help, -h Show this help message
--version, -v Show version information

Examples:
cachesim-js -t trace.vscsi --type vscsi -a lru -s 10mb
Expand All @@ -75,6 +81,11 @@ function main() {
return;
}

if (options.version) {
console.log(`libcachesim-node v${libCacheSim.getVersion()}`);
return;
}

// Check that all required parameters are provided
if (!options.trace || !options.type || !options.algorithm || !options.size) {
console.error('Error: All parameters are required.');
Expand Down
18 changes: 16 additions & 2 deletions libCacheSim-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,30 @@ function getSupportedTraceTypes() {
return ['vscsi', 'csv', 'txt', 'binary', 'oracle'];
}

/**
* Get the version of the libCacheSim Node.js binding
* @returns {string} Version string
*/
function getVersion() {
try {
const packageJson = require('./package.json');
return packageJson.version;
} catch (error) {
return 'unknown';
}
}

module.exports = {
runSimulation,
runSim,
getSupportedAlgorithms,
getSupportedTraceTypes
getSupportedTraceTypes,
getVersion
};

// Example usage if run directly
if (require.main === module) {
console.log('libCacheSim Node.js Bindings');
console.log(`libCacheSim Node.js Bindings v${getVersion()}`);
console.log('Supported algorithms:', getSupportedAlgorithms());
console.log('Supported trace types:', getSupportedTraceTypes());

Expand Down
2 changes: 1 addition & 1 deletion libCacheSim-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libcachesim-node",
"version": "1.0.0",
"version": "1.0.1",
"main": "index.js",
"bin": {
"cachesim-js": "./cli.js"
Expand Down
25 changes: 17 additions & 8 deletions libCacheSim-node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function runTests() {
assert(typeof libCacheSim.runSim === 'function', 'runSim function exists') &&
assert(typeof libCacheSim.runSimulation === 'function', 'runSimulation function exists') &&
assert(typeof libCacheSim.getSupportedAlgorithms === 'function', 'getSupportedAlgorithms function exists') &&
assert(typeof libCacheSim.getSupportedTraceTypes === 'function', 'getSupportedTraceTypes function exists');
assert(typeof libCacheSim.getSupportedTraceTypes === 'function', 'getSupportedTraceTypes function exists') &&
assert(typeof libCacheSim.getVersion === 'function', 'getVersion function exists');
});

// Test 2: Check supported algorithms
Expand All @@ -75,7 +76,15 @@ function runTests() {
assert(traceTypes.includes('csv'), 'Includes CSV');
});

// Test 4: Run default simulation
// Test 4: Check version function
test('Get version', () => {
const version = libCacheSim.getVersion();
return assert(typeof version === 'string', 'Returns a string') &&
assert(version.length > 0, 'Version is not empty') &&
assert(/^\d+\.\d+\.\d+/.test(version), 'Version follows semantic versioning format');
});

// Test 5: Run default simulation
test('Run default simulation', () => {
const result = libCacheSim.runSim();
return assert(typeof result === 'object', 'Returns an object') &&
Expand All @@ -88,7 +97,7 @@ function runTests() {
assert(Math.abs(result.hitRatio + result.missRatio - 1.0) < 0.0001, 'Hit ratio + miss ratio ≈ 1.0');
});

// Test 5: Run custom simulation with different algorithms
// Test 6: Run custom simulation with different algorithms
test('Run custom simulations with different algorithms', () => {
const algorithms = ['lru', 'fifo', 's3fifo'];
let allPassed = true;
Expand All @@ -110,7 +119,7 @@ function runTests() {
return allPassed;
});

// Test 6: Test different cache sizes
// Test 7: Test different cache sizes
test('Test different cache sizes', () => {
const sizes = ['512kb', '1mb', '2mb'];
let allPassed = true;
Expand All @@ -131,7 +140,7 @@ function runTests() {
return allPassed;
});

// Test 7: Error handling - invalid trace file
// Test 8: Error handling - invalid trace file
test('Error handling for invalid trace file', () => {
try {
libCacheSim.runSimulation('/nonexistent/file.vscsi', 'vscsi', 'lru', '1mb');
Expand All @@ -141,7 +150,7 @@ function runTests() {
}
});

// Test 8: Error handling - invalid algorithm
// Test 9: Error handling - invalid algorithm
test('Error handling for invalid algorithm', () => {
try {
libCacheSim.runSimulation('../data/cloudPhysicsIO.vscsi', 'vscsi', 'invalid_algo', '1mb');
Expand All @@ -151,7 +160,7 @@ function runTests() {
}
});

// Test 9: Error handling - invalid trace type
// Test 10: Error handling - invalid trace type
test('Error handling for invalid trace type', () => {
try {
libCacheSim.runSimulation('../data/cloudPhysicsIO.vscsi', 'invalid_type', 'lru', '1mb');
Expand All @@ -161,7 +170,7 @@ function runTests() {
}
});

// Test 10: Performance test - measure execution time
// Test 11: Performance test - measure execution time
test('Performance measurement', () => {
const startTime = process.hrtime.bigint();
const result = libCacheSim.runSim();
Expand Down
5 changes: 1 addition & 4 deletions libCacheSim/include/config.h.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

/* not used */

#define VERSION_MAJOR @libCacheSim_VERSION_MAJOR @
#define VERSION_MINOR @libCacheSim_VERSION_MINOR @
#define VERSION_PATCH @libCacheSim_VERSION_PATCH @

#define VERSION_STRING \
"@libCacheSim_VERSION_MAJOR@.@libCacheSim_VERSION_MINOR@.@libCacheSim_" \
"VERSION_PATCH@"
#define VERSION_STRING "@libCacheSim_VERSION_MAJOR@.@libCacheSim_VERSION_MINOR@.@libCacheSim_VERSION_PATCH@"

#cmakedefine HASH_TYPE @HASH_TYPE @

Expand Down
Loading