-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (123 loc) · 4.57 KB
/
Makefile
File metadata and controls
140 lines (123 loc) · 4.57 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
TIMES ?= 1
VTARGET ?= bug_file/*.v;origin_file/*.v
N ?= 1
WORKSPACE ?= output
RESULT ?= result
DUTDIR ?= dutcache
comma := ;
T_LIST := $(subst $(comma), ,$(strip $(VTARGET)))
$(info >>> VTARGET_LIST is [$(T_LIST)])
DUT_NAME := $(firstword $(subst _, ,$(notdir $(DUT_FILE))))
DUT_BASE := $(basename $(notdir $(DUT_FILE)))
define RANDOM_PORT
while true; do \
port=$$(shuf -i 1024-65535 -n 1); \
if ss -lntu | awk -v port=$${port} 'NR > 1 {split($$5,a,":"); if (a[length(a)] == port) exit 0} END {exit 1}'; then \
continue; \
fi; \
echo $${port}; \
break; \
done
endef
PORT ?= $(shell $(call RANDOM_PORT))
PORT := $(PORT)
OLDPORT ?= 5000
CONTINUE ?= false
IFLOW_VERSION ?= latest
##########################################################################
clean:
@rm -rf $(WORKSPACE)
echo "clean $(WORKSPACE)"
clean_result:
@rm -rf $(RESULT)
echo "clean $(RESULT)"
clean_dut_cache:
@rm -rf $(DUTDIR)
echo "clean $(RESULT) $(DUTDIR)"
clean_all: clean clean_result clean_dut_cache
init:
@mkdir -p $(WORKSPACE)/$(PORT)
@mkdir -p $(RESULT)/$(PORT)
@mkdir -p $(DUTDIR)
@if [ "$(CONTINUE)" = "false" ]; then \
echo ">>> remove $(WORKSPACE)/$(PORT)/*" \
rm -rf $(WORKSPACE)/$(PORT)/*; \
fi
build_one_dut:
@if [ ! -d "$(DUTDIR)/$(DUT_BASE)/$(DUT_NAME)" ]; then \
picker export $(DUT_FILE) --rw 1 --sname $(DUT_NAME) \
--tdir $(DUTDIR)/$(DUT_BASE)/ -c -w /tmp/$(DUT_BASE)_$(PORT).fst; \
fi
build_dut_cache:
@for p in $(T_LIST); do \
for m in `find $$p`; do \
$(MAKE) build_one_dut DUT_FILE=$$m DUTDIR=$(DUTDIR) PORT=$(PORT); \
done; \
done
run_list_mcp:
@for p in $(T_LIST); do \
for m in `find $$p`; do \
$(MAKE) run_one_mcp DUT_FILE=$$m N=$$N PORT=$(PORT); \
done; \
done
run_seq_mcp:
@i=1; \
while [ $$i -le $(TIMES) ]; do \
$(MAKE) run_list_mcp N=$$i VTARGET=$(VTARGET) PORT=$(PORT); \
i=$$((i+1)); \
done
@echo "`date`: All runs completed." >> $(RESULT)/$(PORT)/run_log.txt
@echo true > $(WORKSPACE)/$(PORT)/all_complete.txt
run_one_mcp: init
@echo "`date`: " $(N) $(DUT_FILE) ">>>>>" $(DUT_NAME) ">>>>" $(DUT_BASE) ">>>>" $(PORT) >> $(RESULT)/$(PORT)/run_log.txt
$(MAKE) build_one_dut DUT_FILE=$(DUT_FILE) DUT_NAME=$(DUT_NAME) DUT_BASE=$(DUT_BASE) DUTDIR=$(DUTDIR) PORT=$(PORT)
@if [ ! -d "$(WORKSPACE)/$(PORT)/$(DUT_NAME)" ]; then \
cp -r $(DUTDIR)/$(DUT_BASE)/$(DUT_NAME) $(WORKSPACE)/$(PORT)/; \
echo "Copy dut $(DUT_NAME) complete"; \
fi
@cp spec/$(DUT_NAME)*.md $(WORKSPACE)/$(PORT)/$(DUT_NAME)/
@ucagent $(WORKSPACE)/$(PORT)/ $(DUT_NAME) -s -hm \
--tui --mcp-server-no-file-tools --no-embed-tools -eoc --mcp-server-port $(PORT) $(UCARGS)
# Only save the result when ucagent is normal exit
@bash -lc 'IS_CMP=$$(cd "$(WORKSPACE)/$(PORT)/" && ucagent --hook-message "continue|quit"); \
if [[ "$$IS_CMP" = "/quit" ]]; then \
cp -r $(WORKSPACE)/$(PORT) $(RESULT)/$(PORT)/RUN_$(N)_$(DUT_BASE); \
echo "Copy result $(N)_$(DUT_BASE) complete"; \
fi'
@echo "Waiting for DUT completion signal..."
@while [ ! -f "$(WORKSPACE)/$(PORT)/dut_complete.txt" ]; do \
sleep 5; \
done
run_seq_cagent:
@while true; do \
if [ -e "$(WORKSPACE)/$(PORT)/all_complete.txt" ]; then \
exit 0; \
fi; \
$(MAKE) run_one_cagent PORT=$(PORT); \
done
run_one_cagent:
@while [ ! -e "$(WORKSPACE)/$(PORT)/Guide_Doc/dut_fixture.md" ] || \
[ -e "$(WORKSPACE)/$(PORT)/dut_complete.txt" ]; do \
sleep 5; \
if [ -e "$(WORKSPACE)/$(PORT)/all_complete.txt" ]; then \
exit 0; \
fi; \
done
# Run iFlow CLI
# You can modify the corresponding startup code according to different Code Agent
mkdir -p $(WORKSPACE)/$(PORT)/.iflow
cp ~/.iflow/settings.json $(WORKSPACE)/$(PORT)/.iflow/settings.json
sed -i "s/$(OLDPORT)\/mcp/$(PORT)\/mcp/" $(WORKSPACE)/$(PORT)/.iflow/settings.json
(sleep 10; tmux send-keys `ucagent --hook-message cagent_init`; sleep 1; tmux send-keys Enter)&
cd $(WORKSPACE)/$(PORT) && npx -y @iflow-ai/iflow-cli@$(IFLOW_VERSION) -y && (echo true > dut_complete.txt)
@echo "`date`: DUT iflow execution completed." >> $(RESULT)/$(PORT)/run_log.txt
run:
tmux kill-session -t hk_batch_cagent_session_$(PORT) || true
tmux new-session -d -s hk_batch_cagent_session_$(PORT)
tmux send-keys -t hk_batch_cagent_session_$(PORT):0.0 \
"make run_seq_mcp PORT=$(PORT) OLDPORT=$(OLDPORT) WORKSPACE=$(WORKSPACE) RESULT=$(RESULT) \
TIMES=$(TIMES) VTARGET=$(VTARGET)" C-m
tmux split-window -h -t hk_batch_cagent_session_$(PORT):0.0
tmux send-keys -t hk_batch_cagent_session_$(PORT):0.1 \
"make run_seq_cagent PORT=$(PORT) OLDPORT=$(OLDPORT) WORKSPACE=$(WORKSPACE) RESULT=$(RESULT)" C-m
tmux attach-session -t hk_batch_cagent_session_$(PORT)