uppaal-to-tchecker
Version:
JavaScript implementation of Uppaal to TChecker translator - convert Uppaal timed automata models to TChecker format
127 lines (107 loc) • 4.67 kB
JavaScript
/**
* Verify installation script
* Tests that the uppaal-to-tchecker package is working correctly
*/
const fs = require('fs').promises;
const path = require('path');
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);
const testModel = `
// Test model for verification
clock x;
int counter = 0;
chan sync_channel;
process Producer() {
state idle, producing;
init idle;
trans idle -> producing { guard counter < 5; sync sync_channel!; assign counter++; },
producing -> idle { guard x >= 1; assign x = 0; };
}
process Consumer() {
state waiting, consuming;
init waiting;
trans waiting -> consuming { sync sync_channel?; },
consuming -> waiting { guard x >= 2; assign x = 0; };
}
system Producer, Consumer;
`;
async function main() {
console.log('🔍 Verifying uppaal-to-tchecker installation...\n');
try {
// Test 1: Check if CLI is available
console.log('1. Testing CLI availability...');
const { stdout: version } = await execAsync('utot --version');
console.log(` ✅ CLI available: ${version.trim()}\n`);
// Test 2: Test programmatic API
console.log('2. Testing programmatic API...');
const UppaalToTChecker = require('../src/index');
const translator = new UppaalToTChecker();
console.log(' ✅ API import successful\n');
// Test 3: Test translation
console.log('3. Testing translation functionality...');
const result = await translator.translate(testModel, {
systemName: 'VerificationTest',
verbose: 0
});
if (result.includes('system:VerificationTest') &&
result.includes('process:Producer') &&
result.includes('process:Consumer') &&
result.includes('sync:Producer@sync_channel_emit:Consumer@sync_channel_recv')) {
console.log(' ✅ Translation successful\n');
} else {
throw new Error('Translation output validation failed');
}
// Test 4: Test format detection
console.log('4. Testing format detection...');
const xmlModel = '<?xml version="1.0"?><nta></nta>';
if (translator.detectFormat(xmlModel) === 'xml' &&
translator.detectFormat(testModel) === 'xta') {
console.log(' ✅ Format detection working\n');
} else {
throw new Error('Format detection failed');
}
// Test 5: Test CLI with actual translation
console.log('5. Testing CLI translation...');
const tempInput = path.join(__dirname, 'temp-test.xta');
const tempOutput = path.join(__dirname, 'temp-test.tck');
await fs.writeFile(tempInput, testModel);
try {
await execAsync(`utot "${tempInput}" "${tempOutput}"`);
const outputContent = await fs.readFile(tempOutput, 'utf8');
if (outputContent.includes('system:temp_test')) {
console.log(' ✅ CLI translation successful\n');
} else {
throw new Error('CLI translation validation failed');
}
} finally {
// Clean up temp files
try {
await fs.unlink(tempInput);
await fs.unlink(tempOutput);
} catch (e) {
// Ignore cleanup errors
}
}
// Success summary
console.log('🎉 All tests passed! Installation verification successful.\n');
console.log('📖 Usage examples:');
console.log(' CLI: utot input.xta output.tck');
console.log(' API: const translator = new UppaalToTChecker();');
console.log(' const result = await translator.translateFile("input.xta");\n');
console.log('📚 Documentation: README.md');
console.log('🔗 Examples: examples/ directory');
} catch (error) {
console.error('❌ Installation verification failed:');
console.error(` Error: ${error.message}\n`);
console.log('🛠️ Troubleshooting:');
console.log(' 1. Ensure Node.js >= 14.0.0 is installed');
console.log(' 2. Try reinstalling: npm install -g uppaal-to-tchecker');
console.log(' 3. Check permissions for global installation');
console.log(' 4. Try local installation: npm install uppaal-to-tchecker');
console.log(' 5. Check issues: https://github.com/your-repo/issues');
process.exit(1);
}
}
main();