-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembly_environment_diagnostic.lua
More file actions
364 lines (302 loc) · 12 KB
/
assembly_environment_diagnostic.lua
File metadata and controls
364 lines (302 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/env lua
-- Comprehensive Assembly Development Environment Diagnostic
-- This script systematically tests all components and identifies potential issues
local function log(level, message)
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
print(string.format("[%s] %s: %s", timestamp, level, message))
end
local function file_exists(path)
local file = io.open(path, "r")
if file then
file:close()
return true
end
return false
end
local function test_lua_syntax(file_path)
if not file_exists(file_path) then
return false, "File does not exist"
end
local chunk, err = loadfile(file_path)
if chunk then
return true, "Syntax valid"
else
return false, err or "Unknown syntax error"
end
end
-- Test 1: File Structure Verification
local function test_file_structure()
log("INFO", "=== Testing File Structure ===")
local required_files = {
"files/dotfiles/nvim/.config/nvim/lua/plugins/asm_lsp.lua",
"files/dotfiles/nvim/.config/nvim/lua/custom_arm_docs.lua",
"files/dotfiles/nvim/.config/nvim/lua/asm_utils.lua",
"files/dotfiles/nvim/.config/nvim/snippets/asm.lua",
"files/dotfiles/nvim/.config/nvim/docs/ASSEMBLY_DEVELOPMENT.md",
"files/dotfiles/nvim/.config/nvim/examples/arm64_hello_world.s"
}
local issues = {}
local passed = 0
for _, file in ipairs(required_files) do
if file_exists(file) then
log("PASS", "File exists: " .. file)
passed = passed + 1
else
log("FAIL", "Missing file: " .. file)
table.insert(issues, "Missing: " .. file)
end
end
return {
total = #required_files,
passed = passed,
issues = issues
}
end
-- Test 2: Template Coverage Analysis
local function test_template_coverage()
log("INFO", "=== Testing Template Coverage ===")
local architectures = {"arm64", "x86_64", "arm32", "riscv"}
local template_types = {"asm-lsp", "compile_flags", "Makefile"}
local missing_templates = {}
local existing_templates = {}
for _, arch in ipairs(architectures) do
for _, template_type in ipairs(template_types) do
local extension = ""
if template_type == "asm-lsp" then
extension = ".toml"
elseif template_type == "compile_flags" then
extension = ".txt"
end
local template_file = string.format("files/dotfiles/nvim/.config/nvim/templates/%s_%s%s",
template_type, arch, extension)
if file_exists(template_file) then
table.insert(existing_templates, template_file)
log("PASS", "Template exists: " .. template_file)
else
table.insert(missing_templates, template_file)
log("WARN", "Template missing: " .. template_file)
end
end
end
return {
existing = existing_templates,
missing = missing_templates,
coverage_percent = (#existing_templates / (#existing_templates + #missing_templates)) * 100
}
end
-- Test 3: Lua Module Syntax Validation
local function test_lua_modules()
log("INFO", "=== Testing Lua Module Syntax ===")
local lua_files = {
"files/dotfiles/nvim/.config/nvim/lua/plugins/asm_lsp.lua",
"files/dotfiles/nvim/.config/nvim/lua/custom_arm_docs.lua",
"files/dotfiles/nvim/.config/nvim/lua/asm_utils.lua",
"files/dotfiles/nvim/.config/nvim/snippets/asm.lua"
}
local syntax_issues = {}
local passed = 0
for _, file in ipairs(lua_files) do
local valid, error_msg = test_lua_syntax(file)
if valid then
log("PASS", "Syntax valid: " .. file)
passed = passed + 1
else
log("FAIL", "Syntax error in " .. file .. ": " .. error_msg)
table.insert(syntax_issues, {file = file, error = error_msg})
end
end
return {
total = #lua_files,
passed = passed,
issues = syntax_issues
}
end
-- Test 4: Architecture Detection Logic Analysis
local function test_architecture_detection()
log("INFO", "=== Testing Architecture Detection Logic ===")
-- Test file extension detection patterns
local test_files = {
"test.s",
"test.S",
"test.asm",
"test.inc",
"arm64_test.s",
"x86_test.asm",
"riscv_test.s",
"hello.arm",
"program.aarch64"
}
local detection_issues = {}
-- This is a simplified test - in real implementation, we'd need to load the actual module
for _, filename in ipairs(test_files) do
local extension = filename:match("%.([^%.]+)$")
local valid_extensions = {s = true, S = true, asm = true, inc = true, arm = true, aarch64 = true, riscv = true}
if valid_extensions[extension] then
log("PASS", "Valid assembly file: " .. filename)
else
log("WARN", "Unrecognized extension: " .. filename)
table.insert(detection_issues, "Unrecognized: " .. filename)
end
end
return {
issues = detection_issues
}
end
-- Test 5: Cross-Platform Compatibility Check
local function test_cross_platform_compatibility()
log("INFO", "=== Testing Cross-Platform Compatibility ===")
local issues = {}
-- Check for hardcoded paths or platform-specific code
local files_to_check = {
"files/dotfiles/nvim/.config/nvim/lua/custom_arm_docs.lua"
}
for _, file in ipairs(files_to_check) do
if file_exists(file) then
local f = io.open(file, "r")
if f then
local content = f:read("*all")
f:close()
-- Check for cross-platform URL opening
if content:match("vim%.fn%.has%('mac'%)") and
content:match("vim%.fn%.has%('unix'%)") and
content:match("vim%.fn%.has%('win32'%)") then
log("PASS", "Cross-platform URL opening detected in " .. file)
else
log("WARN", "Potential cross-platform issue in " .. file)
table.insert(issues, "Cross-platform concern: " .. file)
end
end
end
end
return {
issues = issues
}
end
-- Test 6: GNU Stow Compatibility
local function test_stow_compatibility()
log("INFO", "=== Testing GNU Stow Compatibility ===")
local issues = {}
-- Check directory structure
local base_path = "files/dotfiles/nvim/.config/nvim/"
-- Verify no conflicting files
local potential_conflicts = {
"files/dotfiles/nvim/.config/nvim/init.lua",
"files/dotfiles/nvim/.config/nvim/lua/init.lua"
}
for _, conflict_file in ipairs(potential_conflicts) do
if file_exists(conflict_file) then
log("WARN", "Potential Stow conflict: " .. conflict_file)
table.insert(issues, "Conflict: " .. conflict_file)
else
log("PASS", "No conflict: " .. conflict_file)
end
end
return {
issues = issues
}
end
-- Test 7: Error Handling Validation
local function test_error_handling()
log("INFO", "=== Testing Error Handling ===")
local issues = {}
-- Check for proper error handling patterns in Lua files
local files_to_check = {
"files/dotfiles/nvim/.config/nvim/lua/plugins/asm_lsp.lua",
"files/dotfiles/nvim/.config/nvim/lua/custom_arm_docs.lua",
"files/dotfiles/nvim/.config/nvim/lua/asm_utils.lua"
}
for _, file in ipairs(files_to_check) do
if file_exists(file) then
local f = io.open(file, "r")
if f then
local content = f:read("*all")
f:close()
-- Check for pcall usage (protected calls)
local pcall_count = 0
for _ in content:gmatch("pcall") do
pcall_count = pcall_count + 1
end
if pcall_count > 0 then
log("PASS", "Error handling (pcall) found in " .. file .. " (" .. pcall_count .. " instances)")
else
log("WARN", "Limited error handling in " .. file)
table.insert(issues, "Limited error handling: " .. file)
end
end
end
end
return {
issues = issues
}
end
-- Main diagnostic function
local function run_comprehensive_diagnostic()
log("INFO", "Starting Comprehensive Assembly Development Environment Diagnostic")
log("INFO", "================================================================")
local results = {
file_structure = test_file_structure(),
template_coverage = test_template_coverage(),
lua_modules = test_lua_modules(),
architecture_detection = test_architecture_detection(),
cross_platform = test_cross_platform_compatibility(),
stow_compatibility = test_stow_compatibility(),
error_handling = test_error_handling()
}
-- Generate comprehensive report
log("INFO", "")
log("INFO", "=== DIAGNOSTIC SUMMARY ===")
-- File Structure Summary
log("INFO", string.format("File Structure: %d/%d files present (%.1f%%)",
results.file_structure.passed,
results.file_structure.total,
(results.file_structure.passed / results.file_structure.total) * 100))
-- Template Coverage Summary
log("INFO", string.format("Template Coverage: %.1f%% (%d existing, %d missing)",
results.template_coverage.coverage_percent,
#results.template_coverage.existing,
#results.template_coverage.missing))
-- Lua Module Syntax Summary
log("INFO", string.format("Lua Syntax: %d/%d modules valid (%.1f%%)",
results.lua_modules.passed,
results.lua_modules.total,
(results.lua_modules.passed / results.lua_modules.total) * 100))
-- Critical Issues Summary
local critical_issues = 0
critical_issues = critical_issues + #results.file_structure.issues
critical_issues = critical_issues + #results.lua_modules.issues
critical_issues = critical_issues + #results.template_coverage.missing
log("INFO", "")
log("INFO", "=== CRITICAL ISSUES IDENTIFIED ===")
if #results.file_structure.issues > 0 then
log("ERROR", "Missing Core Files:")
for _, issue in ipairs(results.file_structure.issues) do
log("ERROR", " - " .. issue)
end
end
if #results.lua_modules.issues > 0 then
log("ERROR", "Lua Syntax Errors:")
for _, issue in ipairs(results.lua_modules.issues) do
log("ERROR", " - " .. issue.file .. ": " .. issue.error)
end
end
if #results.template_coverage.missing > 0 then
log("WARN", "Missing Templates (Multi-Architecture Support Incomplete):")
for _, template in ipairs(results.template_coverage.missing) do
log("WARN", " - " .. template)
end
end
-- Deployment Readiness Assessment
log("INFO", "")
log("INFO", "=== DEPLOYMENT READINESS ASSESSMENT ===")
if critical_issues == 0 then
log("PASS", "✅ READY FOR DEPLOYMENT - All critical components functional")
elseif #results.lua_modules.issues == 0 and #results.file_structure.issues == 0 then
log("WARN", "⚠️ PARTIAL DEPLOYMENT READY - Core functional, missing multi-arch templates")
log("WARN", " Recommendation: Deploy for ARM64-only environments")
else
log("FAIL", "❌ NOT READY FOR DEPLOYMENT - Critical issues must be resolved")
end
return results
end
-- Execute diagnostic
return run_comprehensive_diagnostic()